Intent

It provide an interface for creating a group of objects without specifying their concrete classes.

Where to use & benefits

we can use this pattern whenever we want

Structure


Participants

AbstractFactory  (IShapeAbstractFactory)
declares an interface for operations that create abstract product objects

ConcreteFactory   (RedRectangleFactory,  (BlueCircleFactory)
implements the operations to create concrete product objects

AbstractProduct  (IShapeFactory, IColorFactory)
declares an interface for a type of product object.

ConcreteProduct  (ShapeFactory, ColorFactory)

Client   (MainApplet)
uses only interfaces declared by AbstractFactory and AbstractProduct classes.

Example

In the demonstration application, ColorShapeFactory class uses ShapeFactory and ColorFactory classes to create the colored shape objects.

Class Diagram


Source Code Links