Open/Closed Principle (OCP)
The Open/Closed Principle states that software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. This means that the behavior of a module can be extended without modifying its source code.
Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.
Benefits:
- Enhances code flexibility: New functionality can be added with minimal changes to existing code.
- Reduces the risk of bugs: Existing code remains unchanged, reducing the risk of introducing new bugs.
- Promotes code reuse: Extensible designs are more reusable.