liveBook · Manning

Open-closed principle

Also called OCP

The open-closed principle is a software design principle stating that software entities should be open to extension but closed to modification.

How 4 Manning books explain it

Grokking Software Architecture

A software design principle stating that software entities should be open to extension but closed to modification.

How it is used
Guides separation of stable behavior from functionality likely to change, from classes to service interactions.
How deep it goes
Explains the principle through contrasting implementations and extends it to service-level design, including a consistency tradeoff.
Examples
Uses soccer plays, a payment-provider-dependent checkout, and order events consumed by rewards and analytics services.
What you can do after
Evaluate code and service designs for changes that could instead be accommodated through stable contracts or subscriptions.

Read how Grokking Software Architecture explains open-closed principle →

Software Design for Python Programmers

The Open-Closed Principle states that a class should be closed to modification but open to extension.

How it is used
Uses stable superclasses and focused extensions to add behavior without propagating modifications through dependent classes.
How deep it goes
Explains superclass design, private state, inherited calls, abstract methods, and runtime strategies, while warning against unnecessary subclass complexity.
Examples
Demonstrates book attributes, mammals, and sports whose specialized subclasses or strategies extend stable common implementations.
What you can do after
Build it from scratch by isolating common behavior, hiding implementation details, and adding specialized subclasses or interchangeable strategies.

Read how Software Design for Python Programmers explains open-closed principle →

Object-Oriented Software Design in C++

A design principle stating that software entities should be closed for modification but open for extension.

How it is used
Uses stable superclasses and specialized subclasses to add book or animal functionality without changing common code.
How deep it goes
Explains stability, encapsulation, subclass extension, and warning signs but stops short of prescribing inheritance for every design.
Examples
Demonstrates book attributes, Shape subclasses, and Mammal subclasses including Human and Cat.
What you can do after
Evaluate designs for stable common abstractions, useful extensions, hidden implementation, and harmful subclass or type-checking growth.

Read how Object-Oriented Software Design in C++ explains open-closed principle →

AI-Powered Developer: Build software with ChatGPT and Copilot

A software-design principle stating that software entities should be open for extension but closed for modification.

How it is used
Guides an extensible IT asset-management model as new asset types and depreciation behaviors are introduced.
How deep it goes
Defines OCP briefly and illustrates it through inheritance and strategy-interface changes, without developing a fuller implementation procedure.
Examples
Uses an Asset–Hardware hierarchy, possible Software and Pitchfork subclasses, and multiple depreciation strategies.
What you can do after
Evaluate/understand whether a class model can accept new asset types or calculation strategies without modifying established entities.

Read how AI-Powered Developer: Build software with ChatGPT and Copilot explains open-closed principle →

Also covered in

What to know first

Related concepts

Questions about open-closed principle

What is open-closed principle?

The open-closed principle is a software design principle stating that software entities should be open to extension but closed to modification.

Which Manning books explain open-closed principle?

Grokking Software Architecture, Software Design for Python Programmers, Object-Oriented Software Design in C++ and AI-Powered Developer: Build software with ChatGPT and Copilot.

What should I know before learning open-closed principle?

Manning books that teach open-closed principle usually introduce object-oriented programming, interface, coupling and polymorphism first.

What is the difference between open-closed principle and handler?

The open-closed principle is a software design principle stating that software entities should be open to extension but closed to modification. A software component that responds to an input by performing the processing or platform-specific actions associated with it.

What is open-closed principle a kind of?

Open-closed principle is a kind of SOLID principles. The SOLID principles are five object-oriented software design guidelines concerning responsibility, extensibility, substitutability, interface design, and dependency direction.

What is open-closed principle also called?

Open-closed principle is also called OCP.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.