During prototyping a simple ddd application from public transit domain I've faced a problem with one value object - Transit Pass:
Each Customer can buy a transit
Pass thatallows a passenger of the service to take either a certain number of pre-purchased trips or unlimited trips within a fixed period of time. A detailed description of these passes is represented in instances of
PassDefinitions. A Customer selects
PassDefinition that is most appropriate for him and receives a new
In the real word, Customer
Passes so it's pretty straightforward to put
Account aggregate as a value object that has a pointer to
PassDefinition. This approach has 2 problems:
- What if administrator will delete
Passobjects may point to deleted
PassDefinitionand inconsistency in context will arise.
- There will be a method (hasEligiblePass) on
Passhas no information about validity, vehicleAllowed etc external call to
PassDefinitionwill be required.
Another option is to move
PassDefinition aggregate. But:
- What if Customer will delete
Account(while it is unlikely since the account can be activated/deactivated only by design)?
- It's very common operation in the system to list all available
Passes for specific
PassDefinitionwill force such trivial operation to retrieve
PassDefinitions and filter many results.
So the global problem is that
Pass lifecycle depends on
PassDefinition lifecycles. How to deal with such objects in DDD?