While learning about design patterns, I came to understand the most frequently used term, Factory Pattern as well as Abstract factory pattern. I searched the internet and came across numerous learning points. After a lot of search and study, I endeavored to find an actual need for the abstract design pattern.
In this article, I will explore this pattern in an easy way so that everyone can have a better understanding of it. Down the level, I'm using a Car (Vehicle) example to demonstrate abstract factory pattern.
An important aspect of software design is the manner in which objects are created. Thus, it is not only important what an object does or what it models, but also in what manner it was created.
Reference: http://www.dofactory.com/
Definition
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Definition
I'd keep the structure in such a way as depicted below.
Participants
The classes and objects participating in this pattern are:
- AbstractFactory (IVehicleFactory)
- declares an interface for operations that create abstract products.
- ConcreteFactory (MarutiFactory, TataFactory)
- implements the operations to create concrete product objects.
- AbstractProduct (ICarEngine, ICarLight)
- declares an interface for a type of product object.
- Product (DDis, LED, Revtron, Helogan)
- defines a product object to be created by the corresponding concrete factory.
- implements the AbstractProduct interface.
- Client (Clinet)
- uses interfaces declared by AbstractFactory and AbstractProduct classes.
Implementation
Run your application now. The following window will appear.
Put the desired car name you would like to know the information about, like Maruti, Tata etc.
Kindly refer to the following window as a result after you put Maruti.