Abstract Factory Pattern
This pattern comes under creational patterns which are widely used in programming constructs: “This Pattern provide the best way to create the Objects.”
“Abstract Factory Patternis used to make the Abstract Factory Class (Base-Factory) which is inherited by the Sub Factories class. All objects of the Sub Factories are accessible with the help of the Abstract Factory. The Abstract Factory is sometimes called Factory of Factories (Sub Factories). Only Interface is responsible to create the group of related object without specifying their class. Sub Factories generate the specific Object with the help of interface”.
Explanation (for complete understanding)
- In my previous article, I took the example of the Vehicle factory which produces the sub objects of car/Bike/Rickshaw which is inherited by the IVehicle Interface. We request the VehicleFactory which generates the respective objects and we must specify what kind of object we need, either car/Bike/Rickshaw.
- Let’s say we talk about air vehicles and sea vehicles. At this point the Factory pattern is not able to fulfill the requirements nor tell the complete information about the sea or air vehicle because of the specifies to the specific type of the vehicle either sea, air, or road, because modularization is one of the key principles which applies when we design the software.
- So what do we the programmers think we should make the super Factories which are responsible to create the sub factories so the sub factories further give the information about the objects using the “Interface" if we want to get information about the engine?
- At that point first of all the use is Interacting with the Abstract Factory. The abstract factory tells the user what kind of vehicle type information you want. If we say, ok give me the information about the engine of the Passenger ship, the Abstract Factory returns the object of the sea Vehicle Factory which is the sub-Class (Sub-Factory) of the Abstract Factory class which contains the all information of the engine regarding the sea Vehicles.
- So we get the object of the sub Factory, which is responsible for generating the object of the specific type in the form of IVehicle interface Object.
Implementations
We have 3 types of vehicle families,

And,

And,













Rajanikant HawaldarPosted Oct 24, 2022, 11:40 AM
Hello Humza, is there any Principal violation due to the problem that SeaVehicleFactory, RoadVehicleFactory and AirVehicleFactory have to implement all three methods but only one of them has a valid body?
Azad AliPosted Oct 8, 2018, 12:59 AM
Nice Article
Anshu BudhirajaPosted Nov 10, 2017, 3:29 AM
The problem here is that SeaVehicleFactory, RoadVehicleFactory and AirVehicleFactory have to implement all three methods but only one of them has a valid body.
Vignesh ManiPosted Jun 9, 2016, 4:52 AM
Good one
Santhakumar MunuswamyPosted Jun 8, 2016, 11:29 PM
Welcome
Santhakumar MunuswamyPosted Jun 8, 2016, 11:29 PM
Good Start
Asad AliPosted Jun 8, 2016, 10:58 AM
Well explained Hamza