Open-closed principle
The open-closed principle ( principle of openness and closure, OCP for short ) is a principle in the object-oriented design of software . It deals with the expandability of existing software.
Bertrand Meyer describes the open-closed principle as follows:
"Modules should be both open (for extension) and closed (for modification)."
"Modules should be both open (for extensions) and closed (for modifications)."
With modules are meant here software units, which can be modules as well as classes , methods etc.
An extension in the sense of the open-closed principle is, for example, inheritance. This does not change the existing behavior of the unit, but extends the unit with additional functions or data. Overridden methods do not change the behavior of the base class either, only that of the derived class. If one also follows Liskov's substitution principle , even overwritten methods do not change the behavior, only the algorithms.
See also
- SOLID - The "O" in "SOLID" stands for the open-closed principle
Individual evidence
- ^ Bertrand Meyer: Object Oriented Software Construction . Prentice Hall, 1988, ISBN 978-0-13-629155-8 , pp. 57-61 .