Open-Closed Principle

OCP

  • Objects or entities should be open for extension but closed for modification.
  • A class should be extendable without modifying the class itself
When modifying some module for adding a new feature,  If I should modify another modules use it, It's too hard work. So if we stick to OCP, We can add new operations easy without modification. Open for extension is not adding a function but adding a new type and Closed for modification means high level policy shouldn't be modified. DIP and Abstraction is required for OCP. Abstraction are two ways for OCP. First is extension for abstract class. Second is implementation of interface. Therefore OCP linked Polymorphism one of the features OOP.






Comments