(OCP) Open-Closed Principle

The Open-Closed Principle (OCP) is a principle of software design that states that a module or class should be open for extension but closed for modification. In other words, the design of a class or module should allow adding new functionality without changing its existing code.

The idea behind OCP is to make the software more flexible, maintainable, and scalable by reducing the risk of unintended side effects from changing existing code. To achieve this, the software should be designed in a way that new functionality can be added through inheritance, composition, or other forms of extension, rather than changing the existing code.

For example, if you have a class that represents a basic shape, you could add new shapes by creating new classes that inherit from the original shape class, rather than changing the code of the original class. This way, you can add new shapes without affecting the existing code, and the original class remains closed for modification.

OCP is one of the five SOLID principles of object-oriented software design, which provide a set of guidelines for designing software that is easy to maintain, test, and extend.

http://principles-wiki.net/principles:open-closed_principle