The Open/Closed Principle (OCP) is the SOLID design principle, associated with Bertrand Meyer and Robert C. Martin, that software entities should be open for extension but closed for modification. New behaviour comes from adding new code, not from changing existing working code. Plugin or strategy-based extension mechanisms, such as the GoF Strategy pattern, are common ways to achieve this.
SOLID-Open/Closed Principle
Details
- Full Name
-
SOLID Open/Closed Principle (OCP)
Intent:
Software entities should be open for extension but closed for modification. Add new behavior by adding new code, not changing existing code.
When to Use:
-
Adding new features requires modifying existing working code
-
Frequent changes to a module break other parts of the system
-
You need a plugin or strategy-based extension mechanism
Prompt Example:
"Refactore diesen Code nach dem SOLID-Open/Closed Principle, sodass neue Varianten ohne Änderung des bestehenden Codes hinzugefügt werden können."
Related Anchors:
-
SOLID Principles (Umbrella)
-
GoF-Strategy Pattern - Common OCP implementation