Inheritance and Behavioral Contracts

A subtype used through a common interface should satisfy the behavior that interface promises for supported calls.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Check an accepted operation
  2. Test via the common interface

Check an accepted operation

Suppose a queue interface promises insertion for any valid job until capacity is reached. A subtype silently discarding jobs from one ordinary category changes that promise. Function contracts apply even when the method dispatch is dynamic.

Test via the common interface

Run a shared contract test for each supported implementation. Add a subtype-specific check only for behavior exposed through its own interface. Postconditions help state stable results and effects.[1]

References

  1. Python Software Foundation, Python Tutorial: Classes ↩