34. class Update[A,E] {
val aggregate : A
val event : E
}
trait EventHandler {
def handle(update:Update[_,_])
}
35. Zachowanie a zmiana stanu
NO BEHAVIOR in state changing methods, no
conditional logic, no exceptions
- Greg Young
36. class Order {
//zachowania
def confirm() : List[DomainEvent]
def addLine(productId:UID):
List[DomainEvent]
//brak logiki
def apply(event:DomainEvent):Order
}
37. Encje jako ADT - case class
case class Order(id:String,
lines:List[OrderLine]){
def addOrderLine(line:OrderLine)=
def confirm() = ...
def cancel() = ...
}
39. Bonus - FSM
case class PreOrder(...) extends Order {
def confirm : OrderConfirmed
def apply(e:OrderConfirmed) :
ConfirmedOrder
}
case class ConfirmedOrder(..) extends
Order {
def send() : OrderSent
}
40. Bonus - testy
When did you read test to assure sth
hasn't happened?
- Greg Young
46. Walidacje - przykad kodu
Funktor walidacji
scalaz.Validation[Error,_]
//przykadowa metoda
nonEmpty(val:String) : Validation[Error,
String]
47. Walidacje - przykad kodu
?
Error("empty.name")
for {
name <- nonEmpty(command.name)
48. Walidacje - przykad kodu
for {
name <- nonEmpty(command.name)
size <- geq(0, command.size)
?
Error("negative.size")
49. Walidacje - przykad kodu
for {
name <- nonEmpty(command.name)
size <- geq(0, command.size)
} yield addCompany(name,size)
?
Error("bad.company")
50. Walidacje - przykad kodu
for {
name <- nonEmpty(command.name)
size <- geq(0, command.size)
} yield addCompany(name,size)
?
CompanyAdded(...)
51. Walidacja bez wyjtk坦w
Non-breaking error handling is just an
applicative functor on a partially applied disjoint
union type constructor with semigroup error
elements so what's the big deal?!
- Tony Morris