Design patterns implementation examples

Abstract factory

Definition:

Creates objects of more than one family (releted or depenedent on each other) without forcing client to use real class names. This is posible thanks to interface AbstractFactory whose implementation object is called "factory", a client uses needed sets of objects for production (each factory's method produces one family).


Example:

An analogy to the every day’s life would be for instance choosing a company in a trade. A company supplies/creates a set of compatible products (subordinated or related) from one field. For instance if we decide that company "S” will be our electronic equipment supplier we have to stick to it because for instance Smart TV from company "S" is compatible with smartphone from the same company and will not be compatible with smartphone from company "T". In other words we choose a supplier for a set of products. As client company we use general names (prevailing) meaning we want to have a TV and a mobile phone and therefore we are not interested in full names such as Company Model1


C++ code:

/src/abstractfactory.cpp
Download source code

Abstract factory UML class diagram:
Abstract factory UML class diagram

Abstract factory UML sequence diagram:
Abstract factory UML sequence diagram