Abstract Factory Design Pattern with real life example in PHP

If you don’t know about Factory Pattern. Please check out my previous article. I already write about it Factory design pattern with real-life example (PHP)
What is an abstract factory design pattern?
Abstract Factory design pattern is one of the Creational pattern. Abstract Factory pattern is almost similar to Factory Pattern is considered as another layer of abstraction over factory pattern. Abstract Factory patterns work around a super-factory which creates other factories.
Simply Say
Abstract factory purpose it to create an abstraction for creation of family of products, so you can easily change it to different family.
I know it’s difficult to understand in theory. It’s better to create a scenario.
Story
If you go outside your country or city. Maybe you booked a hotel. This hotel has package types like standard & premium type. You can select any package right? Let’s build our booking system using an abstract factory design pattern.
First, we create Package
an abstract class. Package
will extends
all package.
Now it’s time to create a package e.g Standard, Premium. This class will extend the Package abstract class.
Our package creates done. Now we create a factory for packages. CreateBookingFactory class has one create method. This method create only a package.
Now we create factories for all packages.
At the end position now we need to create the factory of a factory. Maybe notice BookingFactory
returning a Factory

🤗 I hope everyone enjoys it.
🙋 Follow & Subscribe: https://proghasan.medium.com/subscribe
Design Pattern
- Factory design pattern with real-life example (PHP)
- Abstract Factory Design Pattern with real life example in PHP