One problem I've had with Domain Driven Design is coming up with good realistic examples that exhibit the sorts of complexity we need to be thinking about, without getting lost in the weeds.
My latest idea is to try working through a purchase approval in an analog office.
Bob wants the company to pay for something. So he gets a blank form, and fills in the details, and drops off the form with Alice. Alice does the work of comparing the details to the current policies, and approving / rejecting the request. The resolved request is returned to Bob, so that he can act on the decision that has been made.
There are a lot of requests, and checking the details is a lot of work. So Alice has become a bottleneck. She offloads some of the work to Terry the intern; Terry does the legwork for requests when the approval doesn't require Alice's domain expertise.
As a proxy for easy, we'll use a trivial condition like "amount less than 100 USD".
The form acts as a sort of lock; an actor in this protocol can only change the paper when they have physical control of it. So the process is serial, only one person can record information at a time.
That means we need to think more precisely about how the requests are shared by Alice and Terry. Perhaps all requests go first to Alice, and she passes the easy requests to Terry; or perhaps the requests all go to Terry, and the hard cases are forwarded to Alice.
We can think of the request as a single form, that gets modified. Alternatively, we can think of an envelope filled with "immutable" documents; each actor adds new paperwork to the envelope.
The process is asynchronous, in this sense - the request can be in Alice's office even though Alice herself is out at lunch, or home sick. The movement of paper allows the people to communicate, even though they aren't necessarily in the office at the same time.
The paperwork is anemic - all of the domain knowledge is locked in the heads of Alice and Terry (and, to some degree, Bob). The paperwork is just the bookkeeping.
It's also worth noting that the paper is immutable, in this sense: once the paperwork has left Bob's control, he cannot correct errors until the paperwork is returned to him.
Bob's "view" of this process is the stack of blank forms, and his collection of resolved requests. Alice and Terry have similar views: stacks of pending requests.
Exercise 1: what changes when we take this process digital? So instead of physical paperwork moving from place to place, we now have information being copied from one place to another.
Exercise 2: what changes when we extend the digital process to automate Terry's work?
No comments:
Post a Comment