Overview
KStateMachine is a Kotlin DSL library for creating state machines and statecharts.
The library follows concepts from the following great and well known works and specs:
- Statecharts: A visual formalism for complex systems
- State Chart XML (SCXML)
- Unified Modeling Language
Workflow
Building blocks (main interfaces) of the library:
StateMachine- is a collection of states and transitions between them, processes events when startedIState- states where state machine can go toTransition- is an operation of moving from one state to anotherEvent- is a base interface for events which are processed by state machine and may trigger transitions
Working with state machine consists of two major sequential phases:
- Creation with initial setup and starting
- Processing events, on which state machine can switch its states and notify about changes
val machine = createStateMachine(scope) {
// Setup is made in this block ...
}
// After setup and start, it is ready to process events
machine.processEvent(FirstEvent)
// ...
machine.processEvent(OtherEvent)