Skip to content

Latest commit

 

History

History

README.md

Abstract factory (Kit)

The abstract factory pattern is about delegating the creation of objects to a special object called Factory. A client code that asks the factory to create objects on its behalf is coupled only with the generic interface that a concrete factory implements. Therefore various concrete factories are interchangeable.

Moreover the concrete classes of created objects are hidden from clients behind their interfaces. So these classes are also interchangeable. Usually the objects created by a concrete factory belong to the same family.

See https://en.wikipedia.org/wiki/Abstract_factory_pattern for more information.

Implementation

Abstract factory pattern class diagram

Imagine that some html renderer or any other client code needs to create a set of these html entities :

The client code should not be aware of a concrete class implementing these interfaces. To achieve this the client code does not create these objects directly, instead it asks any object that implements HTMLFactoryInterface (AbstractFactory) to do it. This interface has methods to create: