Tuesday, March 16, 2010

Object Oriented design principles (OOD) - JAVA

All the major Object Oriented Design Principles are mentioned here with their corresponding design pattern examples.


1. The Accessibility minimization of Classes and Members by 
    following concepts 
  • Encapsulation
  • Abstraction
  • Use Accessors and Mutators, Not Public Members
2. Favor Composition over Inheritance
    Example - Strategy Pattern


3. Encapsulate what varies in the Design implementation and 
    keep it separate
    Example - Strategy Pattern
      
4. Program to an Interface, not an Implementation
    In case of Java, prefer Interface inheritance(Sub typing) to 
    Class inheritance  


5. Go for loosely coupled designs between objects that interact
    Example - Observer Pattern


6. The Open-Close Principle - Software entities should be open for 
    extension, but closed for modification.
    Example - Decorator Pattern
  • Its corollary is "The Single Choice Principle" which says - Whenever a Software system must support a set of alternatives, ideally only one class in the system knows the entire set of alternatives
7. Depend on Abstraction, do not depend on concrete classes   
    Example - Factory Method & Abstract Factory


8. Super Classes should call their Sub Classes not vice versa
    Example - Template Method Pattern


9. A class should have only one reason to change
    Example - Iterator & Composite Patterns


10.The Liskov Substitution Principle -  Functions that uses references 
    to the Super Class must be able to use Derived Classes without  
    knowing it.




Please note that any design pattern is usually based on more than one Object Oriented design principles.
examples are given for all the principles, where the pattern mentioned has unique implementation 

1 comment:

  1. Very Nice, I liked your Blog.
    One request to discuss few interview questions asked to you(Some very extraordianry ones, not commonly ones).
    Keep writing brother
    - Ami Jha

    ReplyDelete