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.

    1. Open Closed Principle is only realized by polymorphism if a class only depends on the public contract of the other classes it interacts with.

      1. 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.

  1. Overview Tutorial

  1. Applicability

      1. When defining new class apply this principle as early as possible

      2. Change analysis is key to find problems.

  1. Example

  1. Related Principle

      1. SRP

      2. LSP

  2. Related Patterns

  1. 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