liveBook · Manning

Polymorphism

As explained in Grokking Software Architecture

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

Polymorphism lets different objects respond to the same command in their own ways. A single operation can hide different implementations behind a shared action. section 3.4

One Share button, different actions

Tap Share on a photo: an email app attaches it to a draft, a messaging app puts it in a text, and a social app creates a post. The command stays the same; each app handles it differently. section 3.4

A treatment room for new patient types

A generic TreatmentRoom can handle different Patient types, including a type added later, without changing the room’s code. This illustrates how polymorphism can support extensibility. section 3.8

How Grokking Software Architecture covers it

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.
How it connects
Connects polymorphism to object-oriented programming, virtual methods, inheritance, and the Open/Closed Principle.

Also explained in

Compare how 12 books explain polymorphism →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.