DDD: What kinds of behavior should I put on a domain entity?

前端 未结 4 1093
栀梦
栀梦 2021-02-05 07:34

My team tries very hard to stick to Domain Driven Design as an architectural strategy. But, most of the time, our domain entities are pretty anemic. We\'d like to be putting mor

4条回答
  •  广开言路
    2021-02-05 07:58

    some behavior that i try to put into my domain, entities or value objects.

    validation before persistence. validation before transition into a new state. For example order aggregate root entity can validate its internal state and its aggregate children before going into state Sent. minimize get set properties and use value objects as much as you can. First it makes the model richer with behavior. the entities get more descriptive. second you more rarely put your entity into a invalid state if you must use value object methods like ApplyAdress method on a person entity which takes an Adress Value object as in parameter.

    what more... Info intelligence. use your entity and its value objects to control and restrict aggregate information. like personidentity can be a value object that handles the uniqeuness of a person. it incapsulate ssn, ssn algoritm, handle gender checksum on ssn etc.

提交回复
热议问题