Abstract Factory Pattern
This lesson details the working of yet another creational design pattern, that allows us to create a family of products in a flexible and extensible manner.
What is it ?
In the previous lesson, we learned the factory method pattern. We saw how we were able to model the variants of the F-16 using the factory method. But there are numerous airplanes other than F-16 that we'll need to represent. Say the client buys a Boeing-747 for the CEO to travel and now wants your software to provide support for this new type of aircraft.
The abstract factory pattern solves the problem of creating families of related products. For instance, F-16 needs an engine, a cockpit, and wings. The Boeing-747 would require the same set of parts but they would be specific to Boeing. Any airplane would require these three related parts but the parts will be plane and vendor specific. Can you see a pattern emerge here? We need a framework for creating the related parts for each airplane, a family of parts for the F-16, a family of parts for the Boeing-747 so on and so forth.
Formally, the abstract factory pattern is defined as defining an interface to create families of related or dependent objects without specifying their concrete classes.
Get hands-on with 1200+ tech skills courses.