Code to the interface principle
A design principle in which code depends on an interface and polymorphic behavior rather than on a specific implementation or subclass.
Software Design for Python Programmers
The Code to the Interface Principle structures code to depend on a superclass interface so it can work with any compatible subclass at runtime.
- How it is used
- Structures clients around superclass interfaces so compatible subclasses can be selected and used at runtime.
- How deep it goes
- Explains interface storage, polymorphic dispatch, delegation, and runtime type checks, while cautioning against unnecessary subclass complexity.
- Examples
- Uses Book, FictionAttrs, CookbookAttrs, Catalogue, Sport, PlayerStrategy, and VenueStrategy as concrete Python examples.
- What you can do after
- Apply it via polymorphism to replace compatible implementations without changing clients that depend on their shared interface.
Read how Software Design for Python Programmers explains code to the interface principle →
Object-Oriented Software Design in C++
A design principle that makes code depend on an interface and polymorphic behavior rather than a specific subclass implementation.
- How it is used
- Uses superclass interfaces and polymorphism to keep application code flexible across multiple runtime subclasses.
- How deep it goes
- Defines the principle and demonstrates refactoring with shapes and books, but stops short of a general implementation checklist.
- Examples
- Demonstrates Shape with Rectangle and Circle, then Book with Fiction, Cookbook, and their attribute subclasses.
- What you can do after
- Evaluate designs for concrete-subclass coupling and apply polymorphic superclass interfaces to support multiple subclasses.
Read how Object-Oriented Software Design in C++ explains code to the interface principle →
What to know first
- inheritanceInheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
- 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
- polymorphismuses · Polymorphism 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.
- superclassuses · A superclass is a class from which another class inherits members, structure, or behavior.
- overrideused by · Overriding is defining a more specific implementation of an inherited or otherwise replaceable operation so that it supplies behavior for a derived type or object.
Questions about code to the interface principle
What is code to the interface principle?
A design principle in which code depends on an interface and polymorphic behavior rather than on a specific implementation or subclass.
Which Manning books explain code to the interface principle?
Software Design for Python Programmers and Object-Oriented Software Design in C++.
What should I know before learning code to the interface principle?
Manning books that teach code to the interface principle usually introduce inheritance and polymorphism first.
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.

