Open-Closed Principle¶
Core Idea¶
A system is partitioned into two regions with opposite stances toward change: a stable kernel closed to modification and an extension surface open to addition. New behavior plugs into the surface, never mutating the kernel. The load-bearing commitment is an asymmetry — additive extension is qualitatively safer than destructive in-place modification — with kernel change gated to stay rare.
How would you explain it like I'm…
Snap-On Blocks
Add, Don't Break
Stable Core, Open Edge
Broad Use¶
- Software design: classes expose abstract interfaces and hooks; new requirements are met by adding subclasses or plugins, not editing the module.
- Constitutional design: an inviolate core of rights paired with an amendable surface of statute, the amendment procedure itself kernel-protected.
- Genetics: deeply conserved core protein domains paired with variable regulatory regions; evolution tinkers with regulation.
- Platform/API design: stable public contracts plus extensible endpoints and plugin systems, evolving a product without breaking integrations.
- Philosophy of science: Lakatosian research programmes protect a "hard core" behind a revisable "protective belt."
- OS architecture: a small immutable microkernel isolated from user-space drivers and services.
Clarity¶
Converts "we need to modify the system" into a checkable distinction — a patch on the surface versus a fork that breaks into the kernel — so the hidden cost of mutating shared structure is surfaced before it is paid.
Manages Complexity¶
Concentrates stability in a small slow region while a larger region evolves cheaply; reasoning about invariants stays local to the kernel and about variability local to the surface, so a faulty extension can be pulled without disturbing the core.
Abstract Reasoning¶
Licenses questions about the topology of permitted change: is the boundary drawn right, are extensions genuinely additive or sneaking modifications through back-channels, has the kernel silently grown? — applying identically to a class hierarchy, a constitution, or a genome.
Knowledge Transfer¶
- Institutional design: write amendment procedures that are themselves kernel-protected, requiring a higher bar than ordinary legislation.
- Reliability engineering: instrument the kernel for change-detection so silent drift into the protected region becomes auditable.
- Molecular biology: selection edits regulation while sparing the catalytic core — the same harden-and-relocate move with no software present.
Example¶
A sorting library defines a Comparator interface and writes sort
once against it: the algorithm-plus-contract is the closed kernel,
conforming comparators are the additive surface, and adding a new
ordering cannot break existing callers — whereas editing compare's
signature would invalidate every implementation at once.
Relationships to Other Primes¶
Parents (1) — more general patterns this builds on
- Open-Closed Principle presupposes Modularity — The file: modularity is 'the prerequisite substrate — a system carved into parts with hidden internals'; OCP layers a directional change-stance (sealed kernel + additive surface + gate) onto a modular partition. Presupposes modularity; adds the additive-vs-destructive asymmetry.
Path to root: Open-Closed Principle → Modularity
Not to Be Confused With¶
- Open-Closed Principle is not the Minimal-Modification Principle because it is a global topological rule declaring a kernel change may never enter, whereas minimal-modification is a local rule to perturb as little as possible when you must edit.
- Open-Closed Principle is not Modularity because modularity decomposes into loosely-coupled parts but says nothing about which may change, whereas this adds a directional change-stance plus the gate.
- Open-Closed Principle is not Refinement because refinement edits in place to sharpen a design, which is exactly what the kernel forbids; its growth is additive accretion on a surface.