`
chelsea
  • 浏览: 118269 次
  • 来自: ...
社区版块
存档分类
最新评论

领域驱动设计: Community discussion and Personal understanding

    博客分类:
 
阅读更多

Service

Service历来是争论的焦点. 批评者认为Service的存在表明了职责的不清晰, 认为Service里的代码是没放对位置的代码, 都应该放到相关的Domain对象如Entity中. 总而言之Service不够OO. Service是Transaction Script. 事实上这未必是Service这个building block的问题, 而是传统的面向对象编程范式的问题. OO长于表达行为, 但局限于单个对象. OO在捕捉对象间的交互方面, 并没什么有力的指导原则. 比如, 当在储蓄账户和信用账户之间转帐的时候, 我是在储蓄账户上定义转出呢, 还是在信用账户上定义转入?

有人认识到了OO的这种缺陷, 试图将交互作为系统概念的一等公民, 与数据等并列, 比如DCI(DataContextInteraction)这种新的范式. 我觉得可以把DDD里的Domain Service作为DCI中Interaction的实现方式.

既然是交互, 命名上就应该是动词. 比如应该是TransferService, 而不是AccountService. 这样更具体的命名可以避免Service通常带来的另外一个问题: 因为名字太过General, 导致越来越多但凡沾点边乱七八糟的代码都往里放, Service成了垃圾箱.

简单一点就是:Action/Interaction 未必是某个class的method,也可以(并且更多情况下是更好的选择)是一个单独的class只带一个execute方法. 这不只是简单的代码级别的不同,而是业务概念的显式表达和隐式表达的区别, 尤其是当这个action涉及多个业务对象的时候, 放在哪个class里也不合适. DCI也是这么看的.

 

Application Logic vs. Business Logic

应用逻辑与业务逻辑. 业务逻辑是当你不用软件而完全手工人工来完成业务时依然存在的逻辑. 应用逻辑是当你用IT系统来优化你的业务时额外引入特定于你当前软件实现的逻辑. 保持这两部分的分离有助于保持核心业务逻辑模型和代码的稳定性. See<<领域驱动设计: More Practice>> for more details

 

Value Object

通常是Immutable的.这样你就不用考虑是Copy还是Refer, 是存个Snapshot还是保证Up-to-date. 你只能换掉它而不是改变它. Value Object 不是 DTO, 它们是完全不同的概念服务于完全不同的目的, 只是凑巧有时实现看起来相同:

In general I'm not fond of DTOs since they provide no additional meaning over pure data structures. In most cases I prefer keeping DTOs outside the domain. -- from ddd google group.

 

DoD (Duplication over Dependency), RoR (Replication over Reuse)

这里说的是Bounded Context. 在同一个Context内部, 我们不会容忍重复. 但不同Context之间, 有时重复是解依赖的手段. 更根本的原则是, 当重复出现的时候, 我们需要搞清楚它们概念上是否就是一回事, 还是两个不同概念只是偶然实现在目前相同.

这里还有很多没想清楚的.

 

Entity + Repository = Active Record

如果把Entity和它的Repository放在一个类里实现就跟Active Record看起来类似了. Repository负责集合操作

 

Query over physical collection

用查询来实现集合, 可以lazy load, 可以解决循环引用. 这个其实跟DDD无关, 只是应用ORM框架时对performance问题的solution.

 

Layered Architecture

这里不是说UI/Domain/DataAccess, 单就模型本身也可能分层. 模型反映解决问题的思路, 但对问题直观的理解和解决往往随着细节的深入而出现各种变化, 对此, 模型可以有不同层次. 高层的模型表达高层的解决方案, 很可能寥寥几个接口和概念就足够; 底下的层次则对应反映深入的问题

 

From DDD google group discussion:

Context

As a point to start to discover the contexts I often look to the organization chart of the company to see which kind of roles/point of view they have. The areas that you identified could be contexts.

Aggregates

Aggregates can be used as a technical tool or a modeling one.

  • As atechnical toolit cope with limits of OR/M and the so in persisting and retrieving objects efficiently.
  • As amodeling toolit cope with entities thatcontainsother entities in the modelled domains (that are quite rare, if you consider that an entity is something that is identifiable by domain expert). the state of aggregated objects can be changed (or observed) only through the aggregated root object.

Aggregates are about controlling consistency and invariants, not about restricting the use of types.

 

Technical vs. Non-technical

  • Parts of DDD that are non-technical, which in my opinion are the most important
  • Howerer, the most expensive errors I have experienced are not related to technical details get wrong (we have very high skilled devs and archs), but in non technical decision taken toohurriedly. These "conceptual aspects" of DDD are the more risky ones.
  • ...(ddd) but it is little related to technique, but learning and understanding, exercise and practise: improved communication through the ubiquitous language,reduced complexity and added flexibility

 

Transaction Script vs. Domain Modeling

By using DDD we are turning the focus away from technical concerns and instead focus our effort to the business domain.I think TransactionScript have their proper place and use, but implementing them in a way mixing business logic with technical concerns is never right. Hence "undisciplined".


In this project I've heard people complain about different things they think is complex. Those people being unfamilliar with DDD but having a long history of working on the system thinks the TS code with mixed concerns and very few abstractions is fine since they see exactly what is going on and they "know" what the context is and how everything works on a detailed level. And they think the DDD approach of separating things into different layers and building abstractions for business concepts just adds complexity. Then we have the newcommers, that don't have any prior DDD-experience either, that struggle with understanding of the domain. Even though DDD is new to them they pretty quickly pick up on the concepts and think it is a great help in understanding the domain. To them it is the TS code that is most complex since it doesn't make any difference between lines of business logic and those of database interaction

 

Utility API for specific usage scenario

The model is the core of the application, not the application itself. If you try to model a domain with an api that mimic the applicative context that will use the model, you poison the domain itself. Actually this was another thing that we learnt the hard way: at first, modelers did add methods (or even extension methods) to entities with the desire to help the application developers. But such helpers, turned to be a source of confusion, unnecessary dependencies and rigidity. Thus the signature you suggested could be useful for some clients of a service using the domain, but such async service api would work like an adapter, a façade to the model itself.

 

 

分享到:
评论

相关推荐

    iOS 10 SDK Development: Creating iPhone and iPad Apps with Swift

    From the community-driven changes in Swift 3 to the overhaul of iOS' Foundation framework to make it more "Swifty," iOS 10 and Xcode 8 mark an "all in" commitment to Swift, and this new edition ...

    School psychology services: Community-based, first-order crisis intervention during the Gulf war

    School psychology services: Community-based, first-order crisis intervention during the Gulf war 376 Porjes KOLVIN, I . , FUNDUDIS, T. (1981). Elective mute children: Psychological development and...

    领域驱动设计实践——架构风格及架构实例

    【领域驱动设计实践——架构风格及架构实例】 领域驱动设计(Domain-Driven Design,简称DDD)是一种以业务领域为中心的软件开发方法,旨在处理复杂的业务逻辑。DDD将业务的核心领域模型置于中心位置,通过限定上...

    如何成为程序员:社区版本How to be a Programmer: Community Version

    本文试图总结出优秀的程序员必须做些什么才能使软件系统对客户和他部分负责的众多同事都成功。

    Pro Python 3: Features and Tools for Professional Development, 3rd Edition EPUB

    This book explores the concepts and features that will improve not only your code but also your understanding of the Python community with insights and details about the Python philosophy. ...

    一个不错的免费UML工具:JUDE community

    JUDE Community是一款优秀的免费UML(统一建模语言)工具,特别适合那些需要绘制基础序列图,以视觉方式辅助文档说明的用户。它以其轻巧、多功能和在Ubuntu等Linux操作系统上的良好兼容性,为用户提供了便捷的替代...

    Wiley.Publishing.Fedora.Linux.Toolbox.1000+.Commands.for.Fedora.CentOS.and.Red.Hat.Power.Users.and.Red.Hat.Power.Users.2008.pdf

    - **Overview of Fedora**: Understanding the history, community, and philosophy behind Fedora. - **Installation Options**: Exploring various methods to install Fedora, including graphical and text-...

    Community CA

    名称: Community Server 2.1 for asp.net 2.0中文正式版(同时支持简体/繁体中文/英文) 日期: 2006/08/13 环境: asp.net 2.0 + SQL Server 2000/SQL Server 2005 + VS.net 2005 演示: http://www.hotzs.com 支持: ...

    Community Core Vision 1.3

    Community Core Vision, CCV for short (aka tbeta), is a open source/cross-platform solution for computer vision and machine sensing. It takes an video input stream and outputs tracking data (e.g. ...

    Ubuntu The Complete Reference

    - **Software Sources**: Explanation of adding and managing software sources, including PPA (Personal Package Archives) and third-party repositories. - **Software Updates**: Best practices for keeping ...

    tldr: Simplified and community-driven man pages.zip

    在信息技术领域,命令行接口(CLI)是程序员和系统管理员的重要工具,而man页面则是这个领域的指南针。然而,传统的man页面通常内容繁多,对于初学者来说可能难以理解和消化。为了简化这一过程,一个名为“tldr”的...

    MySQL最新驱动jar包:5.1.49

    MySQL是世界上最流行的关系型数据库管理系统之一,而MySQL的Java驱动程序,也称为JDBC驱动,是连接Java应用程序与MySQL数据库的关键组件。标题提到的"MySQL最新驱动jar包:5.1.49"指的是用于Java应用程序的MySQL ...

    Analyzing Neural Time Series Data图书

    MATLAB is widely used in scientific research due to its extensive libraries, ease of use, and strong community support. It allows for the implementation of custom algorithms, visualization tools, and...

    Playmaker v1.9.0.p20.zip

    The top-rated visual scripting tool for Unity used in Hearthstone, INSIDE, Hollow Knight, The First Tree, Observation, Dreamfall Chapters and more: Project Showcase Artists and Designers: Realize ...

    vs_Community.rar

    3. 插件生态系统:VS Community的Python插件库丰富,可以扩展其功能,如Python IntelliCode,提供AI驱动的代码补全。 三、安装与配置 1. 下载与安装:首先,你需要访问Microsoft官方网站下载VS Community的安装包...

Global site tag (gtag.js) - Google Analytics