|
|
|
|
|
by mvf4z7
1514 days ago
|
|
Has anyone here actually used DDD for building a significant production system? I have read a lot of material on the subject, and everything always sounds good in theory. But whenever I attempt to put the patterns to practice it seems like there are endless pitfalls and gotcha moments. I would love to see an example repo of a successful implementation. |
|
Applied this to a public transport ticketing system, it has entities like "Patrons", "Tokens", "Trips", "Fares", "Passes", "Stations" etc.
Patrons can be registered or de-registered. Tokens can be Assigned, Unassigned, Blocked. Trips can be Entered, Exited, Completed. Tokens are used by Passengers (which are different to Patrons, think Parent buys a Token for Child that is travelling).
Model each of those Nouns and define the verbs that change them (eg Register Patron leads to a Patron Registered event).
DDD Smells: Words like "create", "delete", "modify". Betterer names are things like "register", "suspend", "assign", etc.
Focus on the Nouns and then the Verbs will follow. A lot of design seems to be on workflows and treat the Nouns as passive things that get changed.
I think of how it would work if people were doing it, not computers.
I want to open an account at a bank.
So there are two actors so far, me, and the bank. There's a Noun, an "account". What can an account do? Well, from that sentence, it can be opened. Who can open one? What is a name for me? Customer? AccountHolder? Client? etc. What are the details about the "bank", it has Branches and Ledgers and etc.
Note that absolutely none of what I've described above is about implementation.
Some of the gotchas are thinking that, for example, de-registering a patron is the same as deleting them. Developers love to model everything as CRUD, whereas CRUD are data operations, not a domain activity. Its very rare that you want to actually delete an entity. Accounts get Closed, but they don't get deleted. They get Archived.