Applied Design Patterns with Java
Creational :: Factory Method (107) {C ch 4}
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.
- classes delegate responsibility to one of several helper
subclasses, and you want to localize the knowledge of which helper subclass is the delegate.
Structure
Participants
Product (Document) - defines the interface of objects the Factory Method
creates.
ConcreteProduct (MyDocument) - implements
the Product interface.
Creator (Application)
- declares
the Factory Method, which returns an object of type Product. Creator may also define a default implementation
of the Factory Method that returns a default ConcreteProduct object.
- may call the Factory Method to create
a Product object.
ConcreteCreator (MyApplication)
- overrides the Factory Method to return an instance of a ConcreteProduct.
Catalog Creational Prev Next