DEV Community

Discussion on: Be cautious when implementing the Open Closed Principle

 
bourzayq_khalid profile image
Khalid BOURZAYQ • Edited

In my example i apply OCP just in time and this what should we do and i Refactor to Open-Closed.

Yagni only applies to capabilities built into the software to support a presumptive feature, it does not apply to effort to make the software easier to modify.

YAGNI

At first reading the open closed principle may seem to be nonsensical. Our languages and our designs do not usually allow new features to be written, compiled, and deployed separately from the rest of the system. We seldom find ourselves in a place where the current system is closed for modification, and yet can be extended with new features.

The Open Closed Principle - The Clean Code Blog by Robert C. Martin (Uncle Bob)

In OCP, the term module includes all discrete software elements, including methods, classes, subsystems, applications, and so forth. Also, the phrase “closed with respect to X” means that clients are not affected if X changes.

Protected Variation:The Importance of Being Closed

Indeed, most commonly we add new features by making a vast number of changes throughout the body of the existing code. We’ve known this was bad long before Martin Fowler wrote the book[2] that labeled it Shotgun Surgery but we still do it.

[2]Hall, 1988. [2] Refactoring, Martin Fowler, Addison Wesley, 1999

The Open Closed Principle - The Clean Code Blog by Robert C. Martin (Uncle Bob)