Creational design patterns


1. Abstract factory pattern

2. Builder pattern

3. Factory method pattern

4. Prototype pattern

5. Singleton pattern


 Factory method pattern - 
                                           we create object without exposing the creation logic to the client.


We're going to create a Shape interface and concrete classes implementing the Shape interface. A factory class ShapeFactory is defined as a next step.























Abstract factory pattern -
                                Abstract Factory patterns work around a super-factory which creates other factories. This factory is also called as factory of factories.

One more label wrapper of factory pattern



Builder pattern -
                             Builder design pattern is to separate the construction of a complex object from its representation



A Builder class builds the final object step by step. This builder is independent of other objects.

Example:  
We have considered a business case of fast-food restaurant where a typical meal could be a burger and a cold drink. Burger could be either a Veg Burger or Chicken Burger and will be packed by a wrapper. Cold drink could be either a coke or pepsi and will be packed in a bottle.








Prototype pattern:
                                Prototype pattern refers to creating duplicate object while keeping performance in mind.
This pattern involves implementing a prototype interface which tells to create a clone of the current object

Example:
                 Volume clone in project





Comments

Popular posts from this blog

Type of Design pattern

What Are Design Patterns and Why Do We Need Them