How to avoid having very large objects with Domain Driven Design

后端 未结 6 852
猫巷女王i
猫巷女王i 2020-12-24 13:29

We are following Domain Driven Design for the implementation of a large website.

However by putting the behaviour on the domain objects we are ending up with some ve

6条回答
  •  天涯浪人
    2020-12-24 13:54

    I ran into the same problem, and I found that using child "manager" objects was the best solution in our case.

    For example, in your case, you might have:

    User u = ...;
    OrderHistoryManager histMan = user.getOrderHistoryManager();
    

    Then you can use the histMan for anything you want. Obviously you thought of this, but I don't know why you want to avoid it. It seperates concerns when you have objects which seem to do too much.

    Think about it this way. If you had a "Human" object, and you had to implement the chew() method. Would you put it on the Human object or the Mouth child object.

提交回复
热议问题