Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eric Evans book - Cargo shipping example

I'm studying the book that forms the bases of DDD, and I'm a bit stuck on understanding the example about Cargo Shipping, in chapter 7.

More specifically, I have following question; Wat is the real purpose of "Delivery History"? In my understanding, it is just a collection of handling events. But if that is the case, why does it have its own entity object? Especially since completion time is part of the Handling Event, I fail to understand the added value in Delivery History...

Any help from smarter people than me is greatly appreciated..

Tom

like image 266
Tom Van Acker Avatar asked Sep 22 '14 09:09

Tom Van Acker


1 Answers

The use of Delivery History is to provide a type of log. Like when you track a parcel online, you can look at the last entry in the Delivery History and this is the last event that happened in the story of delivering the cargo.

In the real-world, a company may phone the shipping company and say "Where is my cargo? It was supposed to be delivered last Tuesday!", an operator can use the software to find the cargo and from the Delivery History the operator can discover from looking at the last entry, that the cargo is delayed in transit, etc.

Evans also states that the delivery can be considered complete when the Delivery History matches the goals of the Delivery Specification. This information is important, so it needs to have business logic around it to ensure the information is correct, valid and most importantly it needs to be persisted. This is why Delivery History is an Entity.

Delivery History reflects what has actually happened to a Cargo, as opposed to the Delivery Specification, which describes goals. A Delivery History object can compute the current Location of the Cargo by analyzing the last load or unload and the destination of the corresponding Carrier Movement. A successful delivery would end with a Delivery History that satisfied the goals of the Delivery Specification.

--- Eric Evans, Domain-driven Design: Tackling Complexity in the Heart of Software


EDIT

On the Cargo class diagram, it does look as though the Delivery History class has references to the Handling Events. In this case, the Delivery History might exist as to:

  • Provide a nice place to put the business logic for querying the delivery history.

  • It might preserve a common term (and possibly physical artifact) used in the Ubiquitous Language of the cargo handling domain.

  • The Delivery History also has access to Carrier Movement events, so it knows when the Carrier has arrived at it's destination port, etc.

  • To put Delivery History specific code in the Handling Events would violate the Single Responsibility Principle.

like image 106
Adrian Thompson Phillips Avatar answered Oct 01 '22 04:10

Adrian Thompson Phillips