What constitutes a rich domain model in a POJO/POCO?

牧云@^-^@ 提交于 2019-12-10 16:48:04

问题


What is the difference between

  • A simple fields-accesors-mutators class
  • A rich-modeled class

What constitutes rich modeling in business-domain classes?


回答1:


"Rich" as used here implies "rich behavior" (as opposed to state).

There is technical behavior and domain behavior. Accessors and mutators are technical; they lack the "why" which defines business interest.

Domain objects represent the "why" and encapsulate the "how". Actually, all objects do that; domain objects do it specifically for business value.

Let's say you, as an employee domain object, have to request a day off of work. You have 2 options:

  1. Tell your manager and he marks the schedule.
  2. Ask your manager for the schedule and mark it.

Model 1 is rich. The "why" (vacation time) encapsulates the "how" (marking the schedule).

Model 2 relegates the manager to a simple property bag and leaks the scheduling abstraction.




回答2:


When your business logic is encapsulated in your business objects. In other words, you have a Business Objects (Domain Model) layer, without the need for a separate Business Logic layer.



来源:https://stackoverflow.com/questions/311608/what-constitutes-a-rich-domain-model-in-a-pojo-poco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!