A.Open Close Principle (OCP)

  1. Summary
    1. Classes should be closed for modification and open for extension.
    2. It recommend to program to interface (or abstract abstract version).
    3. It is actually origin of SRP
    4. It recommend introvert class design that means all the the member of classes will modify itself only. 
    5. Open Closed Principle is only realized by polymorphism if a class only depends on the public contract of the other classes it interacts with.
    6. If a class that uses an abstraction has to downcast to a specific subclass in one section, you're not following the Open Closed Principle.
  2. Overview Tutorial
    1. http://www.oodesign.com/open-close-principle.html
  3. Applicability
    1. When defining new class apply this principle as early as possible
    2. Change analysis is key to find problems.
  4. Example 
  5. Related Principle
    1. SRP
    2. LSP
  6. Related Patterns 
    1. Double Dispatch
    2. Chain of Responsibility
  7. Further Discussion 
    1. SRP Vs OCP: SRP leads OCP compliance. It is an specialized case of OCP or else you can say it is first step to achieve OCP. 
    2. OCP Vs LSP: LSP compliance make you closure to achieve OCP
    3. OCP vs LSP vs SRP: OCP=>>LSP+SRP
  8. Further References
    1. Patterns in Practice:The Open Closed Principle