While searching the web, I came across a list of rules from Eric Evans' book that should be enforced for aggregates:
This all seems fine in theory, but I don't see how these rules would be enforced in the real world.
Take rule 3 for example. Once the root entity has given an exteral object a reference to an internal entity, what's to keep that external object from holding on to the reference beyond the single method or block?
(If the enforcement of this is platform-specific, I would be interested in knowing how this would be enforced within a C#/.NET/NHibernate environment.)
I don't think you should let the aggregate give your external code access to it's entities.
You tell your aggregate what you want to happen and it deals with it.
If we have an aggregate:Car. We don't care about petrol, and wheels, we just drive. We ask the car about things and it answers without giving references to the internals.
We ask: Do we have petrol? Yes. Not: Give me the tank object so I can check if we have petrol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With