Dodo doc > Macros and Templates > Templates > Type With Abstract State
Abstract state allows a same type to change according to the internal state of the instance. The attributes, methods, functions and subtypes can all be redefined for each state.
Example:
class Player is Mutable: __state stopped => method Play(Media) __state started.playing => method Stop() method Pause() __state started.on_pause => method Resume() method Forward(int) .
Use:
Player player player.Play(music) # player state is started.playing, only allows Stop() or Pause()
The abstract state of a variable can be tested by adding an apostrophe and the state name to the matched type (optional).
Example:
player ~ ?'started
If the type is Polymorphic, the abstract state can be included when checking type compatibility.
Example:
T ~ Player'started