Posts

Design Patterns in OOP PHP - Factory Method

Image
  Design Patterns in OOP PHP course - Factory Method factory method Most popular pattern you Define interface for creating object but let the subclasses decide which class to initiate factory method lets a class defers instantiation to subclasses  Example  we want to have two cars brand each one implements the same interface and two other classes that implements factory interface those class are responsible for creating object from  we will create as following interface car brand have one method two brand classes bmwBrand and benzBrand implements car brand one interface brand factory  two classes implements the brand factory and will be responsible for creating new object from the two brand classes  bmwBrand and benzBrand   carBrandInterface <?php namespace Creational\FactoryMethod ; interface CarBrandInterface {     public function createBrand (); } ? > BenzBrand class <?php namespace Creational\FactoryMethod ; class BenzBran...

Design Patterns in OOP PHP Builder Design Pattern

Image
Design Patterns in OOP PHP Builder Design Pattern  Builder Design Pattern Is to create complex object with  separation of the way object was created and it creation Sperate construction and representation that means we can create different objects from the same construction way   Example  we want to create two different types of cars with the same manufacture process but with different representation This will be include as following: create  car builder interface that have all methods to be implemented . create model classes responsible for inserting data in each builder class cre ate builder  classes that implements car builder interface each class has its own implementation for method create class producer that do the real implementation its constructor will take the car builder interface as parameter and in the runtime it will actually takes the proper class implementation  interface Builder    CarBuilderInterface.php <?php ...

Design Patterns in OOP PHP Abstract Factory

Image
  Abstract Factory design pattern   Abstract Factory  create series of related dependent objects without specifying its blueprint classes usually all the created classes implements the same interface  Example  Imagine we want to calculate price of different types of cars each car has it's own price formula  we will use Abstract Factory Pattern  this will be include as following: interface car which contains the shared methods among all cars type. carType1 class that implements the car interface and have its own private data ,constructor and implements the shared function carType2  class that implements the car interface and have its own private data ,constructor and implements the shared function    abstract Factory Class in this class we have private members that exist in the two classes carType1 , carType2 and if there is members that don't exist in all other classes we but a default value for it so we don't get an ...