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.
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.
Also covered in
- .NET MAUI in Action
- Automating API Delivery
- The Art of Code
- Julia as a Second Language
- .NET in Action, Second Edition
- Clean Applications with Hexagonal ArchitectureIn early access (MEAP)
What to know first
- object-oriented programmingObject-oriented programming is a programming paradigm that organizes software around objects combining state and behavior, often using encapsulation, classes, inheritance, or polymorphism.
- interfaceAn interface is a contract or boundary that specifies the operations, members, or data shape a type or component exposes, without prescribing its complete implementation.
- couplingCoupling is the degree of interdependence between software components, including their dependencies on one another’s structure, behavior, or availability.
- polymorphismPolymorphism is a programming-language capability that lets a common operation or interface work with values of different types, with behavior or implementation determined by the type or value.
Related concepts
- SOLID principleskind of · The SOLID principles are five object-oriented software design guidelines concerning responsibility, extensibility, substitutability, interface design, and dependency direction.
- superclassconfigures · A superclass is a class from which another class inherits members, structure, or behavior.
- separation of concernsaddresses · Separation of concerns is a design principle that organizes a system into parts with distinct responsibilities and limited overlap.
- principlekind of · A principle is a general rule, guideline, or value that guides decisions, behavior, or judgments.
- encapsulationuses · Encapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
- handlercontrasts with · A software component that responds to an input by performing the processing or platform-specific actions associated with it.
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.



