In Meyer's Object-Oriented Software Construction (1988) he defines the open/closed principle as follows:
- A module will be said to be open if it is still available for extension. For example, it should be possible to add fields to the data structures it contains, or new elements to the set of functions it performs.
- A module will be said to be closed if it is available for use by other modules. This assumes that the module has been given a well-defined, stable description (the interface in the sense of information hiding).
He goes on to say:
If you reopen a module, you must also reopen all its clients to update them, since they rely on the old version. … [This problem] arises every time a module must be extended by a new function or data element, triggering changes in direct and indirect clients. ... With classical approaches to design and programming, there is no way to write modules that are both open and closed.
Meyer's solution to this dilemma is: never extend a library module by modifying existing classes; instead, write a new module that subclasses the existing classes, and have new clients depend on that new module.
Now, in 1988, I was was writing toy (procedural) programs in Turbo Pascal and Blankenship Basic, and my 21st-century professional experience is on the JVM, the CLR, and in dynamic languages, so I don't know what Meyer meant by "classical approaches to design and programming".
Meyer's one concrete example of why client modules must be reopened (a switch statement on an enumeration which now has more members, requiring more cases) seems reasonable enough, but he doesn't nearly justify the assertion that every time you add functionality to a library module, you need to update all its clients.
Is there a historical reason that this assertion seemed self-evident in 1988? Did, say, adding functions or data structures to a C static library change the layout such that even with backwards-compatible APIs, clients had to be recompiled? Or is Meyer really just talking around a mechanism for enforcing API backwards compatibility?