Anemic Domain Model是一堆没有定义行为的智能服务和愚蠢对象吗? [英] Is Anemic Domain Model a bundle of smart services and stupid object without a defined behavior?

查看:118
本文介绍了Anemic Domain Model是一堆没有定义行为的智能服务和愚蠢对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于什么是OOP中的贫血域模型,我有些困惑.是一捆无格式的老式X对象(其中X代表您喜欢的语言),没有行为(和责任).

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);
    }
}

它出现在Martin Fowler的 AnemicDomainModel 文章的结尾

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.

推荐答案

通常,您在服务中发现的行为越多,越多 您很可能会抢劫域名的利益 模型.如果您所有的逻辑都在服务中,那么您就被盲目抢劫了.

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.

使用碰巧支持OOP的多范例语言,并不意味着您正在编写面向对象的代码.

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

这篇关于Anemic Domain Model是一堆没有定义行为的智能服务和愚蠢对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆