Refactor to the Open-Closed

These are five words that changed my life. It’s a way to help get out of this rut of legacy code. Refactoring is changing the design without changing the external behavior. The Open-Closed Principle says software entities should be “open for extension but closed for modification.” In other words, strive to make adding any new feature a matter of adding new code and minimally changing existing code. Avoid changing existing code because that’s when new bugs are likely to be introduced.

Refactoring to the Open-Closed is a way to add features to software safely and cost-effectively. Always make every change in a two-step process. First, refactor the code you want to extend so that it can accommodate the new feature. ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.