- 浏览: 118269 次
- 来自: ...
文章分类
最新评论
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
发表评论
-
Architecture is layered
2004-12-11 11:57 379那天被问道软件架构师需要了解编程语言的细节吗? 呵呵,架构是 ... -
Thinking Everyday
2004-12-11 12:01 4371,编程语言的发展趋势 ... -
糟糕命名集锦
2004-12-11 16:50 5681,公交支线,如375和375 ... -
古代的软件开发 (一)
2005-02-19 16:45 6741,额外的中间层鞋子:人类发明鞋子的意义无论如何评价都不过分, ... -
访问控制 : 语言和平台
2005-03-15 19:27 610程序逻辑上的组织方式(如名称空间,包等)可以和部署时的分发 ... -
Thinking Everyday II
2005-03-17 15:11 6181, 是业务,不是技术,傻瓜 是集成,不是编程 是使用,不 ... -
内容与标准为王:下一代互联网与下一代搜索
2005-07-25 14:53 702第一代互联网混淆了真正的数据和它的表现形式,第一代搜索无法 ... -
个性与定制为王:下一代互联网和下一代门户
2005-07-28 11:28 599看一下现在我与互联网有关的生活:我有两三个常用的Web邮箱 ... -
泛型编程 vs. 面向对象
2005-08-10 14:30 815面向对象:封装(数据抽象)是基础,继承是手段,多态是目的 ... -
函数式编程 vs. 对象式编程
2005-08-10 14:44 647<<我爱我家>>有一集和平摔成了脑 ... -
用手机从ATM取钱
2005-11-21 22:49 692手机的以下两个特性,使它潜在的可能成为统一的支付和信用平 ... -
Web 3.0 : Unified Human-like Interaction
2006-01-14 16:31 696你还在到搜索引擎的主页上去搜索吗?你还登录新闻网站查询最新比赛 ... -
软件生物学
2006-01-14 16:59 647长久以来,软件的建筑学隐喻已经深入人心,可始终无法达到建筑 ... -
广义对象论
2006-01-25 15:31 687前几天本想接着以前的思维中对“3.2 Programming ... -
Thinking Everyday III
2006-03-26 14:17 7871, RAII让我告别了delete,IoC让我告别了ne ... -
简单至及的AOP和IOC
2006-03-26 14:21 659I. AOP的例子 1, Google To ... -
TDD: Tricky Driven Development
2007-05-10 07:07 590命名 测试用例的名字应该描述需求, 不要描述实现. ... -
Thinking Everyday IV
2007-05-15 04:36 5191, 实际上 C# 2.0 已经部 ... -
迭代本质论
2008-02-14 13:58 627新年伊始, 可能你又要制定一些计划了, 实际上, 你的生活在开 ... -
建筑的永恒之道
2004-08-10 18:31 6482,质 这种特质是任 ...
相关推荐
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 376 Porjes KOLVIN, I . , FUNDUDIS, T. (1981). Elective mute children: Psychological development and...
【领域驱动设计实践——架构风格及架构实例】 领域驱动设计(Domain-Driven Design,简称DDD)是一种以业务领域为中心的软件开发方法,旨在处理复杂的业务逻辑。DDD将业务的核心领域模型置于中心位置,通过限定上...
本文试图总结出优秀的程序员必须做些什么才能使软件系统对客户和他部分负责的众多同事都成功。
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. ...
JUDE Community是一款优秀的免费UML(统一建模语言)工具,特别适合那些需要绘制基础序列图,以视觉方式辅助文档说明的用户。它以其轻巧、多功能和在Ubuntu等Linux操作系统上的良好兼容性,为用户提供了便捷的替代...
- **Overview of Fedora**: Understanding the history, community, and philosophy behind Fedora. - **Installation Options**: Exploring various methods to install Fedora, including graphical and text-...
名称: 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, 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. ...
- **Software Sources**: Explanation of adding and managing software sources, including PPA (Personal Package Archives) and third-party repositories. - **Software Updates**: Best practices for keeping ...
在信息技术领域,命令行接口(CLI)是程序员和系统管理员的重要工具,而man页面则是这个领域的指南针。然而,传统的man页面通常内容繁多,对于初学者来说可能难以理解和消化。为了简化这一过程,一个名为“tldr”的...
MySQL是世界上最流行的关系型数据库管理系统之一,而MySQL的Java驱动程序,也称为JDBC驱动,是连接Java应用程序与MySQL数据库的关键组件。标题提到的"MySQL最新驱动jar包:5.1.49"指的是用于Java应用程序的MySQL ...
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...
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 ...
3. 插件生态系统:VS Community的Python插件库丰富,可以扩展其功能,如Python IntelliCode,提供AI驱动的代码补全。 三、安装与配置 1. 下载与安装:首先,你需要访问Microsoft官方网站下载VS Community的安装包...