The Expected Call Sequence of an Interface
An interface can specify which operations are allowed in each state, such as open before read and close after use.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Draw three states
A reader could start uninitialized, become open after receiving a source, and become closed when done. Reusing read after close can raise an explicit error. Use a state transition table to document outcomes.
Make cleanup reliable
An ordinary error during reading should still let the caller release the resource. A context-managed file lifetime implements a structured version of that pattern.[1]