Sunday, July 24, 2016

IOC (Inversion of Control)

An entity must concern to its own logic and all unconcerned logic should put inside any other external logic.

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.

SOLID Principles

Is first five object oriented design (OOD) principle given by Robert C. Martin.

S – Single responsibility principle – A class should have one reason to change. Means a class must have only responsibilities related to it.

O – Open-closed principle – Extension should be preferred over modifications. Classes & functions should be open for extension but close for modifications (by sub classing & virtual functions).

L – Liskov substitution principle – Parent type should easily replace its child types (Polymorphism).

I – Interface segregation principle – Means, share only those functionality to clients whichever they want and introduce another more functionalities for new client without affecting old clients.

D – Dependency Inversion Principle – Depending on abstraction not on concretion.
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Abstractions should not depend on details. Details should depend on abstractions.