Provide an iterface for creating families of related or dependent objects without specifying their concreate classes.
Also Known As
Use the Abstract Factory pattern when,
- a System should be independent og how its products are created, composed and represented.
- a System should be configured with one of multiple families of products
- a family of related product objects is designed to be used together and you need to enforce this constaint.
- you want to provide a class library of products and you want to reveal just their interface not their implementation.
- AbstractFactory (WidgetFactory)
- Declares an interface for operations that create abstract product objects.
- ConcreateFactory (MotifWidgetFactory, PMWidgetFactory)
- Implements the operations to create concrete product objects.
- AbstractProduct (Window, ScrollBar)
- Declares an interface for a type of product object
- ConcreteProduct (MotifWindow, MotifScrollBar)
- Defines a prouct object to be craeted by corresponding concrete factory.
- Implemets the AbstractProduct interface
- Uses only interface declared by AbstractFactory and AbstractProduct classes
- Normally a single instance of ConcreteFactory class is created at run-time. This concrete factory creates product objects having a particular implementation. To create different product objects, client should use a different concrete factory.
- AbstractFactory defers creation of product objects to its ConcreteFactory subclass.
The Abstract Factory pattern has the following benifits and liabilities:
- It isolate concrete classes.
- It makes exchanging product families easy.
- It promotes consistency among products.
- Supporting new kinds of product is difficult.