Is Anemic Domain Model a bundle of smart services and stupid object without a defined behavior?

雨燕双飞 提交于 2019-12-25 15:54:13

问题


I am a bit confused about what is a anemic domain model in OOP. Is a sort of bundle of Plain Old X Object (where X stands for the language you prefer), without behaviors (and responsibilities).

class AnemicDomainClass {
    private $property;
    public function getProperty() {
        return $this->property;
    }
    public function setProperty($property) {
        $this->property = $property;
    }
}

... where all the logic is inside some services?

class SomeStuffService {
    public static function doSomething(AnemicDomainClass $class) {
        $class->setProperty(42);
    }
}

This appear at the end of AnemicDomainModel article of Martin Fowler

In general, the more behavior you find in the services, the more likely you are to be robbing yourself of the benefits of a domain model. If all your logic is in services, you've robbed yourself blind.

This means what? That is better to prefer with smart object instead of smart services.


回答1:


In general, the more behavior you find in the services, the more likely you are to be robbing yourself of the benefits of a domain model. If all your logic is in services, you've robbed yourself blind.

It means write object oriented code, instead of procedural code acting on data. Object oriented code means modeling concepts into objects that know their own attributes and behavior, and which collaborate together to represent a working solution to a problem.

Using a multi-paradigm language that happens to support OOP, does not mean you are writing object oriented code.



来源:https://stackoverflow.com/questions/28432192/is-anemic-domain-model-a-bundle-of-smart-services-and-stupid-object-without-a-de

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