© Matthias Noback 2018
Matthias NobackPrinciples of Package Designhttps://doi.org/10.1007/978-1-4842-4119-6_2

2. The Open/Closed Principle

Matthias Noback1 
(1)
Zeist, The Netherlands
 
The Open/Closed principle says that1:

You should be able to extend a class’s behavior without modifying it.

Again, a small linguistic jump has to be made from the name of the principle to its explanation: a unit of code can be considered “open for extension” when its behavior can be easily changed without modifying it. The fact that no actual modification is needed to change the behavior of a unit of code makes it “closed” for modification.

It should be noted that being able to extend a class’s behavior doesn’t mean you should actually extend that class by creating a ...

Get Principles of Package Design: Creating Reusable Software Components 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.