Abstract factory pattern

The abstract factory pattern in software engineering is a design pattern that provides a way to create families of related objects without imposing their concrete classes, by encapsulating a group of individual factories that have a common theme without specifying their concrete classes.

Additionally, higher levels of separation and abstraction can result in systems that are more difficult to debug and maintain.

The pattern describes how to solve such problems: This makes a class independent of how its objects are created.

However, the factory only returns a reference (in Java, for instance, by the new operator) or a pointer of an abstract type to the created concrete object.

[5] An example is an abstract factory class DocumentCreator that provides interfaces to create a number of products (e.g., createLetter() and createResume()).

The system would have any number of derived concrete versions of the DocumentCreator class such asFancyDocumentCreator or ModernDocumentCreator, each with a different implementation of createLetter() and createResume() that would create corresponding objects such asFancyLetter or ModernResume.

The client would only need to know how to handle the abstract Letter or Resume class, not the specific version that was created by the concrete factory.

This design uses native support for interfaces or protocols in mainstream programming languages to avoid inheritance.

UML class diagram