Method Overrides and Dynamic Dispatch
A call through an object may select an overriding implementation according to the object's runtime type and language rules.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Trace the selected method
Suppose a report class formats a heading in plain text and a specialized class provides another heading method. Calling through a specialized instance can choose that override even when code refers to the general report interface. See methods and instances.
Preserve surrounding guarantees
If the rest of the report expects the returned heading to be text, an override returning a list breaks callers. Test the common behavioral contract across supported implementations.[1]