开发者

Can a Boundary Class interact with an Entity Class?

开发者 https://www.devze.com 2023-01-24 04:04 出处:网络
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 En

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:

  1. 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.
  2. 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消