The Abstract Factory design pattern provides a solution:
Encapsulate creating a family of objects
in a separate
factory object.
A class delegates object creation
to a factory object
instead of instantiating concrete classes directly.
Describing the Abstract Factory design in more detail is
the theme of the following sections.
See Applicability section for all problems Abstract Factory can solve.
new ProductA1(), for example)
is abstracted by referring to an interface
(delegating to a factory object):
factory.createProductA().
factory objects:
AbstractFactory | createProductA(),createProductB(),…).
Factory1,…)
that implement the interface.
Client) delegates the responsibility for creating objects
to a factory object
(factory.createProductA(),factory.createProductB(),…).
Background Information
MazeFactory is not an abstract class; thus it
acts as both the
AbstractFactory and the
ConcreteFactory.
This is another common implementation for simple applications of
the Abstract Factory pattern."
[GoF, p94]