For instance: link
Is the开发者_开发百科 above Ok or it would be better to create more methods in Controller that handle the data that are sent/retrieved without the interaction between UI and the Entity?
In general when is it allowed (if it is) for a Boundary Class to interact with an Entity Class?
Depends on whether you want/need to stick religiously to the Boundary-Control-Entity pattern:
- If yes (you do need to stick to the pattern): then no, the Boundary object can only speak to Control objects. See table at bottom of this page (also a good description of pattern).
- If no: then yes it can!
That's not meant to be glib. It's questionable whether such strict separation is good design practice. It looks nice in pictures: Boundary, Control and Entity in nice horizontal layers with messages passing adjacent layers only.
The reality is rather different. Strict separation can lead to two problems:
- A proliferation of pass-through methods. You allude to this. You end up with an amalgamation of methods on the controllers that do nothing more than pass through to the underlying entities.
- Anaemic Entity classes. Rather than the Entities being home for data + behaviour, they become data containers only with all behaviour migrating out to controllers. That's not a good thing.
It's notable that in Domain Driven Design, Eric Evans recommends creating Services (akin to Controllers) only when the logic in question doesn't have a viable home in any of the Domain Classes (Entities).
精彩评论