Sunday, 14 January 2018

Design Patterns | Abstract Factory Pattern

Abstract Factory Pattern is a creational design pattern. It is almost similar to Factory Pattern with another layer of abstraction over factory pattern. Abstract Factory patterns work around a super-factory which creates other factories.

According to the Gang of Four

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

Intent
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

Abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme. It provides an interface (or abstract class) for creating families of related or dependent objects without specifying their concrete classes.

Abstract Factory Pattern is almost similar to Factory Pattern with one more abstraction layer over factory pattern and this layer provides the factory of the factories.



Participants
The classes and objects participating in this pattern are:
AbstractFactory
It declares an interface for operations that create abstract products.
ConcreteFactory
This class implements the operations to create concrete product objects
AbstractProduct
It declares an interface for a type of product object.
Product
It defines a product object to be created by the corresponding concrete factory and implements the AbstractProduct interface.
Client
The client uses interfaces declared by AbstractFactory and AbstractProduct classes.

Abstract Factory Design Pattern in Java Libraries
javax.xml.parsers.DocumentBuilderFactory#newInstance()
javax.xml.transform.TransformerFactory#newInstance()
javax.xml.xpath.XPathFactory#newInstance().

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...