jargon

Design patterns·Objects, messages and the principles

adding the fourth payment method meant editing the same switch statement for the fourth time.

Open–closed principle

Also calledopen closed principle, OCP, open for extension closed for modification

The principle that a module should be extensible without editing its existing source: new behaviour arrives as new code rather than as a change to code that already works. In practice it is achieved by putting the variation behind an abstraction the module calls out to — a strategy, a registered handler, a plugin. The honest caveat is that you cannot make a module open to variation you did not anticipate, so applying it before you know the axis is how speculative generality gets built.

Commonly confused with