Actors Unleashed: Reactive Systems, DDD, and the Ubiquitous … · 2017-06-02 · What Donald Knuth...
Transcript of Actors Unleashed: Reactive Systems, DDD, and the Ubiquitous … · 2017-06-02 · What Donald Knuth...
Actors Unleashed: ReactiveSystems, DDD, and theUbiquitous Language
@VaughnVernonCopyright © 2012-2017 for{comprehension} All rights reserved.
WhatDonald KnuthActually Said:
“We should forget about small efficiencies,say about 97% of the time: prematureoptimization is the root of all evil. Yet weshould not pass up our opportunities in thatcritical 3%.”
AndDonald Knuth
Also Said:“People who are more than casuallyinterested in computers should have at leastsome idea of what the underlying hardware islike. Otherwise the programs they write willbe pretty weird.”
Responding to RapidNew Business Direction
DDD enables necessaryknowledge crunching
Actors and messages enablesrapid implementation and
clear understanding
Actors and DDD
Alan Kay: “The big idea is messaging...”
Alan Kay: “The Actor model retained moreof what I thought were the good
features of the object idea.”
Aggregate
● Immutable state object/record
Implementation
● Transition and replace stateupon command/event
● Emit corresponding event
class Product(productId: String) extends PersistentActor {
override def persistenceId = productId var state: Option[ProductState] = None override def receiveCommand: Receive = { case c: CreateProduct =>
val event = ProductCreated(productId, c.name, ...)
persist(event) { persistedEvent => updateWith(persistedEvent) sender ! CreateProductResult(productId, c.name, ...) } ... } override def receiveRecover: Receive = { case e: ProductCreated => updateWith(e) ... } def updateWith(e: ProductCreated) { state = Option(ProductState(e.name, e.description, false, None)) }}