Abstract Factory Design Pattern & Implementation Using Java


The Abstract Design Pattern is a creational Design Pattern and used to create Family of Objects. The abstract design pattern is very important to design pattern and used in a situation where the user wants to create a family of the object. It is considered as another layer of abstraction over factory pattern.
The Abstract Factory pattern is pretty common in Java code. Many frameworks and libraries use it to provide a way to extend and customize their standard components.

Here are some examples from core Java libraries:




The pattern is easy to recognize by methods, which return a factory object. Then, the factory is used for creating specific sub-components.


Example of Abstract Design Pattern

The designing a car based on location and type is a based example of the abstract design pattern. We will create a car example for Asia and Europe region with car type as Luxury, Sedan, and SUV.
We will create KWDeaultCarFactory, KWAsiaCarFactory & KWEuropeCarFactory class to instantiate Family of cars Object based on CarType and Location. Please see Class Diagram and Source Code below –

We have Implemented Abstract Design Pattern, Please find Source Code using below link –

Source Code V1.0: KWAbstractFactoryDesignPattern Source Code

Source Code V1.1:KWFactoryDesignPattern_V1.1_Source_Code

Leave a Reply

Your email address will not be published. Required fields are marked *