2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Factory Method
|
|
|
|
folder: factory-method
|
2015-08-15 18:03:05 +02:00
|
|
|
permalink: /patterns/factory-method/
|
2015-08-20 21:40:07 +02:00
|
|
|
categories: Creational
|
2015-09-10 15:26:47 +05:30
|
|
|
tags:
|
|
|
|
- Java
|
|
|
|
- Difficulty-Beginner
|
2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
**Intent:** Define an interface for creating an object, but let subclasses
|
|
|
|
decide which class to instantiate. Factory Method lets a class defer
|
|
|
|
instantiation to subclasses.
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
**Applicability:** Use the Factory Method pattern when
|
|
|
|
|
|
|
|
* a class can't anticipate the class of objects it must create
|
|
|
|
* a class wants its subclasses to specify the objects it creates
|
2015-08-15 18:03:05 +02:00
|
|
|
* classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate
|