Monday, 25 July 2022

Types of Design Patterns.

 1) Creational:-

    These design patterns are used when a decision must be made at the time of  instantiation of a class            (i.e.creating an object of a class).

    1. Factory Method Pattern :Factory Method Pattern says that just define an interface or abstract  class for creating an object but let the subclasses decide which class to instantiate
    2. Abstract Factory Pattern :Abstract Factory Pattern says that just define an interface or abstract class for creating families of related (or dependent) objects but without     specifying their concrete sub-classes.
    3. Singleton Pattern: Singleton Pattern says that just"define a class that has only one instance and provides a global point of access to it".In other words, a class must ensure that only single instance should be created and single object can be used by all other classes.

                           There are two forms of singleton design pattern

    •   Early Instantiation: creation of instance at load time.
    •   Lazy Instantiation: creation of instance when required.

               4 . Prototype Pattern: Prototype Pattern says that cloning of an existing object instead of                    creating new one and can also be customised as per the requirement. This pattern should                    be followed, if the cost of creating a new object is expensive and resource intensive.

               5. Builder Pattern: Builder Pattern says that "construct a complex object from simple                         objects using step-by-step approach"  It is mostly used when object can't be created in                        single step like in the de-serialisation of a complex object.

              6.Object Pool Pattern:Object Pool Pattern says that " to reuse the object that                                       are expensive to create". Basically, an Object pool is a container which contains a                               specified amount of objects. When an object is taken from the pool, it is not available in                     the pool until it is put back.Objects in the pool have a lifecycle: creation, validation and                     destroy.

2)Structural :-

      Structural design patterns are concerned with how classes and objects can be composed.

    • Adapter Pattern-Adapting an interface into another according to client expectation.
    • Bridge Pattern  -Separating abstraction (interface) from implementation.
    • Composite Pattern- Allowing clients to operate on hierarchy of objects.
    • Decorator Pattern-Adding functionality to an object dynamically.
    • Facade Pattern-Providing an interface to a set of interfaces.
    • Flyweight Pattern-Reusing an object by sharing it.
    • proxy Pattern -Representing another object.

 3)Behaviour:-

In these design patterns, the interaction between the objects should be in such a way that they can easily talk to each other and still should be loosely coupled.

  1.          Chain of Responsibility Pattern
  2.          Command Pattern
  3.          Interpreter Pattern
  4.          Iterator Pattern
  5.          Mediator Pattern
  6.          Memento Pattern
  7.          Observer Pattern
  8.          State Pattern
  9.          Strategy Pattern
  10.         Template Pattern
  11.         Visitor Pattern
  12.          Null Object