Add to your build
libraryDependencies += "dev.hnaderi" %% "edomata-core" % "0.11.4"
or for scala.js
libraryDependencies += "dev.hnaderi" %%% "edomata-core" % "0.11.4"
Layers of abstraction
Before jumping in to code, we should know the big picture of what we are going to do;
application logic is divided into 2 separate layers:
- is pure and has no side effects at all
- ensures aggregate invariants and implements all business rules and logic
- does not change frequently in well established businesses
- models an aggregate root in DDD
- aggregate roots just hold enough data to decide based on business rules and maintain invariants; they don't care about any other data
- may involve side effects
- is very minimal and mostly gluing
- must be idempotent
- models application services and command handlers in DDD
- each aggregate has a unique address
- all the possible aggregates together, form our aggregate space which is an infinite space (mathematically speaking)
- there is nothing as a non existing aggregate, aggregates that are not created yet do exist in their initial state.
Currently these kinds of state machines are implemented in edomata:
Edomatonwhich is a portmanteau for event driven automaton, and models applications that are event sourced.
Stomaton, which is also a portmanteau (surprisingly) for state driven automaton, and models applications that are simple state machines (without event sourcing); and is especially useful in CQRS style command handling.
That's all we need to know for now; talk is enough, let's jump into code!