liveBook · Manning

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.

How 2 Manning books explain it

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 →

Related concepts

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.