liveBook · Manning

Polymorphism

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.

How 12 Manning books explain it

100 C++ Mistakes and How to Avoid Them

Polymorphism is the ability to use a common interface while selecting behavior according to an object's actual type.

How it is used
Uses polymorphism to design substitutable class hierarchies and handle derived objects through common interfaces.
How deep it goes
Explains virtual dispatch, slicing, destruction, and exception handling through contrasting C++ examples.
Examples
Contrasts Square and Horse inheritance with a Moveable interface and uses Person and Student to illustrate slicing.
What you can do after
Apply it in C++ by designing a shared virtual interface, preserving derived objects, and deleting them safely through base pointers.

Read how 100 C++ Mistakes and How to Avoid Them explains polymorphism →

The Well-Grounded Python Developer: How the pros use Python and Flask

Polymorphism is an object-oriented technique in which the same method call can produce different behavior depending on the object's class or runtime type.

How it is used
Keeps a drawing loop usable across different shapes through a shared draw() call.
How deep it goes
Defines polymorphism and works through inherited and shape-specific draw() methods; stops short of method-dispatch internals.
Examples
Uses Rectangle, Square, and Circle objects in a drawing window, plus a loop that calls draw() on each shape.
What you can do after
Apply it via Python classes to draw a mixed collection of shapes without changing the display loop for each shape.

Read how The Well-Grounded Python Developer: How the pros use Python and Flask explains polymorphism →

Learn C++ by Example

Polymorphism is the ability to invoke a common interface while allowing the actual object's type to determine the implementation.

How it is used
Uses a shared Blob interface to race different movement implementations through base pointers.
How deep it goes
Explains abstract interfaces, overriding, v-table dispatch, virtual destructors, and pointer ownership, stopping short of a complete race implementation.
Examples
Demonstrates racing stepper and random blobs, configuring uniform or normal movement, and testing with deterministic zero-producing callables.
What you can do after
Build polymorphic C++ classes, dispatch through base pointers, combine derived objects, and test implementations with controlled generators.

Read how Learn C++ by Example explains polymorphism →

Data-Oriented Programming: Reduce software complexity

Polymorphism is a language capability in which a common interface can represent values or objects with different implementations.

How it is used
Decouples a common interface from varying implementations while supporting object-oriented and data-oriented designs.
How deep it goes
Explains interfaces, type dispatch, validation, multimethod structure, and dispatch variants without descending into implementation internals.
Examples
Uses dog, cat, and cow greetings, type-based switches, animal maps, schemas, and separate greeting functions.
What you can do after
Builds polymorphic behavior with interfaces, type dispatch, or multimethods while evaluating inheritance and data-oriented trade-offs.

Read how Data-Oriented Programming: Reduce software complexity explains polymorphism →

API Design Patterns

Polymorphism is an object-oriented programming technique that allows common interfaces to be used across different concrete types while hiding type-specific implementation details.

How it is used
Translates object-oriented shared interfaces into resource-oriented APIs that represent and operate on related concrete resource types.
How deep it goes
Explains resource structure, subtype validation, type evolution, behavior, trade-offs, and method restrictions, but not storage implementation.
Examples
Uses Shape, Triangle, Square, Message, mixed-type listings, subtype fields, and a countSides API method.
What you can do after
Design polymorphic resources, validate subtype data, evolve type strings carefully, and avoid methods that constrain future behavior.

Read how API Design Patterns explains polymorphism →

Go by Example

Polymorphism is the ability to treat instances of different types through a shared type or interface while preserving type-specific behavior.

How it is used
Uses interfaces and driver abstractions to make database operations independent of specific database technologies.
How deep it goes
Distinguishes embedding from inheritance, then explains concrete-type driver polymorphism and optional features via type assertions.
Examples
Demonstrates sql.Open with SQLite and PostgreSQL, mediated by *sql.DB and sql/driver interfaces.
What you can do after
Apply it via database/sql by using *sql.DB while drivers handle database-specific behavior.

Read how Go by Example explains polymorphism →

JavaScript in Depth

A classification of a function or operation whose observed inputs have a small, bounded set of relevant types or shapes.

How it is used
Classifies property-load call sites by the number of object shapes they have observed.
How deep it goes
Defines shape thresholds, traces inline-cache transitions, and measures slowdown without detailing optimized machine-code internals.
Examples
Uses a readX function, six differently shaped objects, --log-ic output, and Node.js 24 property-load measurements.
What you can do after
Diagnose property-access slowdowns by correlating observed object shapes with inline-cache states and benchmark results.

Read how JavaScript in Depth explains polymorphism →

Object-Oriented Software Design in C++

Polymorphism is the ability for an object's behavior to vary according to the concrete subclass of the object being referenced.

How it is used
Uses superclass interfaces and runtime dispatch to let callers work with multiple subclass implementations.
How deep it goes
Explains signatures, overriding, virtual functions, pointers, and runtime dispatch through a tax example.
Examples
Demonstrates GeneralTax, LocalTax, and MaxTax calculating different amounts through GeneralTax pointers.
What you can do after
Apply it via C++ virtual functions and subclass overrides to support runtime-varying behavior.

Read how Object-Oriented Software Design in C++ explains polymorphism →

Test Driven: Practical TDD and Acceptance TDD for Java Developers

Polymorphism is the object-oriented capability for objects of different types to provide type-specific behavior through a shared interface.

How it is used
Replaces type-checking conditionals in template rendering with type-specific behavior on Segment objects.
How deep it goes
Works through tests and implementations for two Segment types, without generalizing beyond template rendering.
Examples
Uses plain-text and variable segments to render a template with a map of values.
What you can do after
Build type-specific Segment evaluation behind a shared interface, using tests for plain text and variables.

Read how Test Driven: Practical TDD and Acceptance TDD for Java Developers explains polymorphism →

Go in Action, Second Edition

Polymorphism is the ability to treat values of different concrete types through a shared interface or abstraction.

How it is used
Uses interfaces to share behavior across domain types such as recipe measurements without inheritance or rigid type hierarchies.
How deep it goes
Explains interface contracts and demonstrates concrete measurement conversions, while emphasizing design flexibility rather than runtime internals.
Examples
Demonstrates String methods, Convertible measurements, recipe scaling, unit conversion, and grocery-list generation.
What you can do after
Apply it via Go interfaces to write flexible code that accepts multiple implementations and supports later domain extensions.

Read how Go in Action, Second Edition explains polymorphism →

Grokking Software Architecture

Polymorphism is an object-oriented language feature allowing different objects to respond to the same operation according to their own implementations.

How it is used
Frames polymorphism as a way for objects to handle a shared command differently and for systems to accommodate new types.
How deep it goes
Defines polymorphism through examples and connects it to virtual methods, without detailing implementation mechanics.
Examples
Uses a Share button handled by different apps and a TreatmentRoom that accepts multiple Patient types.
What you can do after
Apply polymorphism to let a handler accommodate a new type without modifying its code.

Read how Grokking Software Architecture explains polymorphism →

Clojure: The Essential Reference

Polymorphism is a programming technique in which one operation can select different implementations according to its inputs or dispatch criteria.

How it is used
Supports extensible behavior across Clojure values while interoperating with Java classes, interfaces, and inheritance.
How deep it goes
Explains metadata dispatch, multimethods, protocols, and type checks with examples, but defers detailed multimethod mechanics.
Examples
Uses metadata-tagged contacts, multimethod formatting, runtime type inspection, and instance? checks against Java classes and interfaces.
What you can do after
Apply it via metadata dispatch or multimethods, and recognize when protocols better replace cascading instance? conditionals.

Read how Clojure: The Essential Reference explains polymorphism →

Also covered in

What to know first

Related concepts

Questions about polymorphism

What is polymorphism?

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.

Which Manning books explain polymorphism?

100 C++ Mistakes and How to Avoid Them, The Well-Grounded Python Developer: How the pros use Python and Flask, Learn C++ by Example, Data-Oriented Programming: Reduce software complexity, API Design Patterns, Go by Example, JavaScript in Depth, Object-Oriented Software Design in C++ and 4 more.

What should I know before learning polymorphism?

Manning books that teach polymorphism usually introduce inheritance, atomic type, Go and method first.

What kinds of polymorphism are there?

Kinds of polymorphism include ad hoc polymorphism, run-time polymorphism and static polymorphism.

What is polymorphism part of?

Polymorphism is part of object-oriented programming. Object-oriented programming is a programming paradigm that organizes software around objects combining state and behavior, often using encapsulation, classes, inheritance, or polymorphism.

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.