域对象/服务和业务逻辑层 [英] Domain objects/services and the Business Logic Layer

查看:185
本文介绍了域对象/服务和业务逻辑层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

软件架构中的域对象和域服务是什么?我不熟悉它们或它们与业务逻辑层的区别?

What are domain objects and domain services in software architecture? I am not familiar with them or how they differ from the business logic layer?

推荐答案

不同的人以不同的方式使用这些术语,但这是我的看法:

Different people use these terms in somewhat different ways, but here's my take:

1)商业和域大致是同义词。 域更为通用,因为它不会假设您正在编写业务应用程序。因此,如果我们正在编写科学应用程序或游戏,我们可能更愿意将代码的相关部分称为域代码而不是业务代码。因此,在本解释的其余部分中,我将使用域,因为它更通用。

1) "Business" and "domain" are roughly synonyms. "Domain" is a bit more general in that it doesn't make the assumption that you're writing a business application. So if we were writing a scientific app or a game, we might prefer to refer to the relevant part of the code as "domain" code rather than "business" code. So in the remainder of this explanation I'll use "domain" since it's more general.

2)域逻辑包含域对象和域服务 。由于各种原因(技术上和其他原因),许多体系结构采用一种设计,其中域逻辑被分成用于存储数据的对象(域对象)和操纵那些的对象(域服务)。 Martin Fowler和其他人已经指出,这不是非常OO 因为OO的很大一部分概念是将功能与数据结合在一起,这是正确的,但事实就是如此。域对象是数据,域服务是与数据相关的部分。

2) "Domain logic" comprehends both "domain objects" and "domain services". For various reasons (technical and otherwise) many architectures employ a design where the domain logic is divided into objects for storing data ("domain objects") and objects that manipulate those ("domain services"). Martin Fowler and others have pointed out that that's not very OO since a big part of the OO concept is to put functionality together with data, and that's right, but it is what it is. Domain objects are the data and domain services are the do-stuff-with-the-data part.

3)在域驱动设计中,想法是回归真正的OO设计,所以各种服务方法回到域对象,以便你有OO意义上的对象,而不是有时被称为贫血的对象。在DDD中,域对象本身更健壮,因此它们形成域逻辑。实际上可能仍然存在一些域服务,但DDD中的这种服务通常比更传统的域对象与服务模型相比更小。

3) In domain-driven design, the idea is to get back to true OO design, and so the various service methods make their way back to the domain objects so that you have objects in the OO sense rather than what are sometimes called "anemic" objects. In a DDD the domain objects themselves are more robust and so they form the domain logic. In reality there may still be some domain services too, but this is typically smaller in a DDD than in a more traditional domain objects vs. services model.

这篇关于域对象/服务和业务逻辑层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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