The Open-Closed Principle

Software clearly needs to be extensible. However, making changes to software runs the risk of introducing problems. This dilemma led Bertrand Meyer to propose the open-closed principle.[1] To paraphrase this principle, the modules, methods, and classes should be open for extension, while closed for modification.[2] In other words, we must design our software so that we can extend the capabilities of our software without changing it.

[1] Meyer, B., Object-Oriented Software Construction, Upper Saddle River, N.J.: Prentice Hall, 1997, p. 57.

[2] See this book's Web site for a link to “The Open-Closed Principle,” an excellent article by Robert C. Martin. Go to http://www.netobjectives.com/dpexplained.

As contradictory as this ...

Get Design Patterns Explained: A New Perspective on Object-Oriented Design 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.