Domain Driven Design - Parent child relation pattern - Specification pattern

前端 未结 3 725
清酒与你
清酒与你 2021-01-02 19:23

I was wondering which of the following is considered to be a best practice when dealing with parent child relationships.

1) The following example seems to be a commo

3条回答
  •  甜味超标
    2021-01-02 19:55

    I tend to use option (1) - has always worked well for me. The important thing is not to expose the children collection itself to the outside world - the Parent should be able to mediate all the access. But I'm perfectly happy for a Child to be created elsewhere - I only care about it when it gets added to the Parent, and at this point it can be checked for validity etc. etc.

    I don't understand your specification example: it seems like your ChildSpecification would return true if any of the parent's children has someCondition as true. Surely IsSatisfiedBy(Child child) should only return true if the specific child passed as a parameter satisfied the condition.

提交回复
热议问题