Avoiding anemic domain model - a real example

后端 未结 4 869
再見小時候
再見小時候 2021-01-29 21:13

I am trying to understand Anemic Domain Models and why they are supposedly an anti-pattern.

Here is a real world example.

I have an Employee class, which has a t

4条回答
  •  后悔当初
    2021-01-29 22:14

    If your domain model contains only roles and things, not activities as behavior, then it is anemic. However, I'm talking about behavior in regards to a model not an object. I talk of the difference between them in another answer... https://stackoverflow.com/a/31780937/116442

    From your question, you break my first two domain analysis modelling rules:-

    1. Behavior modeled as (recorded) Activities are at the heart of a domain model. Add them first.
    2. Model domain activities as Classes, not methods.

    I would add an activity "Enquiry" to the model. With it the model has behavior, and can combine and work as group of objects without an external controller or script.

提交回复
热议问题