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.
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.
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.
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.
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.
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.
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
- Idiomatic Rust
- Practices of the Python Pro
- Building User-Friendly DSLs
- Functional Design and Architecture: Examples in Haskell
- Java Persistence with Spring Data and Hibernate epub
- Software Design for Python Programmers
- Elixir in Action, Third Edition
- Build and Orchestrator in Go (From Scratch)
- Rust in Action: Systems programming concepts and techniques
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.
- atomic typeAn atomic type is a type whose supported accesses and operations are indivisible with respect to concurrent execution and provide defined synchronization semantics.
- GoGo is a statically typed, compiled, general-purpose programming language with garbage collection and built-in support for concurrency.
- methodA method is a callable function or operation associated with a type, class, or object and invoked through that association.
Related concepts
- object-oriented programmingpart of · Object-oriented programming is a programming paradigm that organizes software around objects combining state and behavior, often using encapsulation, classes, inheritance, or polymorphism.
- run-time polymorphismincludes · Run-time polymorphism is the selection of an operation’s implementation during execution according to an object’s dynamic type or interface.
- interfaceused by · An interface is a contract or boundary that specifies the operations, members, or data shape a type or component exposes, without prescribing its complete implementation.
- code to the interface principleused by · A design principle in which code depends on an interface and polymorphic behavior rather than on a specific implementation or subclass.
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.











