domain driven design - DDD: Aggregate boundary vs compositional convenience. -


i'm starting new ddd project , feel haven't grasped concepts yet. have 2 aggregate roots in domain far, recipe , food. relationship :

`recipe`->*`ingredient`->`food` 

an ingredient quantity + food

i think maybe having aggregate (food) in recipe aggregate bad, it's convenient because allows calculate nutritional values of recipe navigating relation.

i not store result of calculation , recalculate every time if food changed recipe updated automatically , don't know if it's idea.

also, ok have single repository recipe+ingredient since in same aggregate , have load ingredients can pass them in constructor of recipe anyway?

is ok have single repository recipe+ingredient since in same aggregate , have load ingredients can pass them in constructor of recipe anyway?

that people expect - single repository loads of state contained within aggregate boundary.

i think maybe having aggregate (food) in recipe aggregate bad, it's convenient because allows calculate nutritional values of recipe navigating relation.

  • the bad outweighs good.
  • this not obvious when using simplified domain discover how ddd.

the motivation aggregates constrain way data in model changes, every change leaves model in internally consistent state.

if domain doesn't have consistency constraints enforce (for instance, when data model database, , data model has no veto power on proposed changes), problem space doesn't offer lot of guidance in choosing aggregate boundaries.

the basic principle behind aggregates creating sort of data firewall, never need worry changes this aggregate going violate rules of that aggregate. implies, among other things, no 2 aggregates should ever share mutable data.

sharing values fine -- each aggregate gets own immutable copy of value, , changing value in 1 aggregate doesn't affect other @ all. sharing entities bad, because entities mutable.

having model makes convenient produce query wrong answers isn't valuable model ensures answers correct.

what happen 1 aggregate reference id. recipe like

`recipe`->*`ingredient`->`id<food>` 

id<food> immutable value type; recipe can change food uses, can't change food in way. in turn means never need worry changing 1 recipe break another.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -