menu

Sunday, July 24, 2016

Design Patterns

Factory Pattern - Creational Pattern - Remove lots of scattered new keywords by introducing a factory class, and stop exposing our concrete classes by introducing a base interface type.

Abstract Factory Pattern - Creational Pattern – It is an extension of factory pattern, in case we have lots of similar kind of factory pattern classes in to one interface.

Builder Pattern - Creational Pattern - Helps if construction process of an object (Invoice) is complex and do I need to separate construction from its representation. It has 3 component.
Builder - Defines the construction of individual parts.
Director - Takes those individual part from builder and define the sequence to build the product.
Product - is the final object. Ex. construction of Tea object like Tea without sugar and tea without milk.

Prototype Pattern - Creational Pattern - Helps us to give a way to create a clone object from existing object. There are 2 type of cloning.
1.  Shallow cloning - When only parent object is being cloned.
2.  Deep cloning - When with parent, its aggregated child objects are also need to be cloned.
Adaptor Pattern - Structural Pattern - Helps us in case of 2 class types are incompatible because of its incompatible interface. These are of 2 type.
1.   Class Adaptor Pattern –
2.  Object Adaptor Pattern –
Collection classes have Add() and Stack class have Push(), here both are doing same thing but Add and Push are not compatible.

Bridge Pattern - Structural Pattern - Helps to decouple abstraction from its implementation.
Composite Pattern - Structural Pattern - Helps to treat different type of objects in uniform manner.
Decorator Pattern – Structural Pattern – Are nothing but the inheritance.

Proxy Pattern – Structural Pattern – Helps in making available heavy object or sensitive object throughout network by sharing parent interface ref object rather than actual object (Web & WCF Service Client).

Template Pattern – Structural Pattern – Helps in generalising something by using abstract class and make specific type by inheriting abstract class. Here abstract class will be like template for all its derived class.

Mediator Pattern – Behavioural Pattern – Helps in communicating component (purchase, payment, checkout etc.) in a loosely coupled manner. Move communication logic from component to mediator.


Iterator Pattern – Behavioural Pattern – Helps by allowing sequential access of element without exposing the inside code.

No comments:

Post a Comment