EMZETT.
Login

OCP

In short: The open-closed principle (OCP) states: software should be open for extension but closed for modification.

In more detail: New functions should be added through new code without changing existing, tested code. It is the “O” in SOLID.

In Depth

Example

Instead of extending a long if chain for shapes (if (type == CIRCLE) ... else if ...), there is an interface Shape with area(). A new shape is a new class, the calling code stays the same (polymorphism).

See SRP, LSP, inheritance.

See also: SOLID-Prinzipien, SRP, LSP, Interface