3 Apr 2016

SOLID Principles

SOLID

Single Responsibility Principle
       There should never be more than one reason for a class to change.

Open Closed Principle
       Module should be open for extension but closed for modification.
      Eg: For existing 10 algorithm, if I have to add 11th algorithm it should allow for extension.

Liskov Substitution Principle
    Functions which uses reference of base class, should be able to use objects of derived class without knowing them.
    Eg: Program generic Interface, and do not refer concrete classes.

Interface Segregation Principle
    Many client interface are better than one generic Interface.

Dependency Inversion Principle
High level modules should not depend on low level modules. Do not depend on many classes, depend on Interfaces or abstractions.
Both should depend on abstractions.
Abstractions should not depend on details.
Details should depend on details.
Program to interface, not to concrete classes.

Fundamentals in OOPS Concepts


Oops Concepts
Abstraction
   focusing on essential characteristics of an object not all.
Encapsulation
   which hides internal details of object.
Modularity
    dividing cohesive and loosely coupled
  
Hierarchy
    (is a)
   (part of) – Aggregation
                       Containment
Aggregation(diamond)
   Inner objects life-time is not controlled by outer object.
Containment
    Inner objects life-time is controlled by outer object.
Polymorphism ( can be Aggregation
    compile
    runtime
Namespace
    Logical naming and grouping

Inheritance:
    It is white-box reusability. Concrete class can easily override the logic in base class.

Composition:
  It is black-box resuse, when I am using the object, I get access its public property but not its private.

Design Patterns (Brief)

9Design Patterns

CREATIONAL ( Object Creation)
1. Factory Method
      creating an instance of several of derived classes.
2. Abstract Factory
     creating a family of classes.
3. Builder
     Builds the object in parts. (step by step)
4. Singleton
     Only one instance of an object to be created.
5. Prototype
       Fully initialized object need to be copied or cloned.

STRUCTURAL
   1. Adapter
           Eg: different classes having different interface, we need adapter to match the interface of classes
2. Bridge
       When product is sold , support team separating the developing team from customer.
3. Composite
     is mainly involved in tree of Simple and composite (complex) objects.
4. Decorator
       used to add responsibility to the object at runtime dynamically.
5. Proxy
      used when you want an object to represent another object.
6. FlyWeight
     used when a fine grained object to be used efficiently.
7. Facade
   single class is representing sub-system. Abstract the complex structure.
BEHAVIOURAL
     1. Chain of Responsibility
              while passing request to chain of objects.
    2.  Command
              encapsulate the request in object
   3. Interpreter
           includes the language element in the program
  4. Iterator
         used when to take out traversal item in the list.
5. Mediator
     When we want to simplify between two objects.
6. Memento
        when we want to capture and restore (Eg: Undo operation)
7. Visitor
       defines new operation to class without changing the class.
8. Template
     differ exact steps to sub class.
9. Strategy
    to encapsulate an algorithm in a class.
10. State
         to alter object behavior only when its state change.
11. Observer
            to notify the change to other objects, (publish and subscriber).