Duck typing
Duck typing is a typing approach in which a value’s suitability is determined by the operations or behavior it provides rather than its declared type.
Go in Practice, Second Edition
Duck typing is a typing approach that determines an object's suitability by the methods and behaviors it provides rather than by explicit nominal declarations.
- How it is used
- Uses method behavior to decide whether independent Go types can satisfy a shared interface.
- How deep it goes
- Explains interface assignment and compile-time method validation, but does not descend into runtime dispatch internals.
- Examples
- Uses Animal, Cat, Dog, and Llama types to demonstrate successful interface assignments, compile errors, and method-based repair.
- What you can do after
- Apply via Go interfaces by designing method signatures and checking type satisfaction through compiler-validated assignments.
Read how Go in Practice, Second Edition explains duck typing →
The Art of Unit Testing 3e
Duck typing is a type-compatibility approach that accepts an object based on the operations it supports rather than its declared type or class.
- How it is used
- Uses object-parameter injection to replace dependencies with controllable stubs during JavaScript tests.
- How deep it goes
- Explains matching function signatures, handwritten fakes, runtime checking, and a compile-time interface alternative.
- Examples
- Uses RealTimeProvider, FakeTimeProvider, PasswordVerifier, getDay(), and a weekend exception test.
- What you can do after
- Apply it via JavaScript object injection to substitute controllable test dependencies and exercise specific behaviors.
Practices of the Python Pro
Duck typing is a typing approach that determines an object's suitability by the presence of the required behavior rather than by its declared class or type.
- How it is used
- Enables polymorphism and swappable implementations by relying on required behavior instead of declared classes.
- How deep it goes
- Explains runtime method checks and shared interfaces, but stops short of formal interface enforcement.
- Examples
- Uses the duck analogy, FancyTire substitution, and command objects sharing execute.
- What you can do after
- Apply it via Python by designing consumers around expected methods and attributes rather than concrete classes.
Related concepts
- mockinguses · Mocking is a testing technique that replaces a real dependency with a controlled substitute to simulate behavior or inspect interactions.
- Pythonuses · Python is a high-level, general-purpose, dynamically typed programming language known for readable syntax and automatic memory management.
- natural language interfaceuses · A natural language interface enables interaction with a system through human-language text or speech.
- iteratoruses · An iterator is an object or abstraction that provides successive values from a sequence or data source through a traversal protocol.
- type checkingcontrasts with · Type checking is the process of determining whether values, expressions, or operations conform to the rules or constraints of a type system.
- contractimplements · An API contract is a specification of the operations, data, and behavioral expectations that govern interactions between software components.
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.


