DDD的关键问题是如何识别缺失的领域概念. Eric的书里提供了一些方法, 比如倾听表达用语, 检查不协调之处, 研究矛盾之处等等. 我们需要更多的实践来捕捉缺失的概念.
新实践: 检查更换编程框架对代码带来的影响.
这个实践基于以下的理念: 业务逻辑没有发生变化则领域模型也不应该变化. 因此如果更换编程框架造成了大量业务代码的变动, 则意味着有概念没有被封装在领域层.
这里并非鼓吹要应用程序可以支持动态的切换编程框架, 比如从一种ORM工具切到另一种, 或者从一种MVC框架切到另一种. 这里强调的是领域模型及领域概念应该独立于编程框架来表达, 虽然最终模型需要通过某种关联或适配被框架来调用.
举个例子. 公司在为客户提供不同的服务之前, 需要按照法律跟客户签署一系列的协议. 这可以是一个 legal compliance 的 sub domain. 如果客户没有签署协议, 则系统拒绝提供进一步的服务. 如果系统是一个网站, 则检查客户的协议签署情况以判断是继续提供服务还是拒绝的逻辑可以放在Filter中(几乎所有web编程框架都提供了基于管道和过滤器的架构). 但如果这样的话, 当我们更换web框架时需要把这部分逻辑挪到新框架下的filter中. 因此更好的做法是把这部分逻辑挪进领域模型, 可以建模成规则, 来表达每一条需要遵守的法律约束, 最终可以用领域层的管道和过滤器连接起来.
我们不必真的更换编程框架, 只需假象一下. 之前有类似的实践, 是假想需要为系统提供不同的UI, 比如一个Web UI和一个命令行UI, 来促使业务逻辑不要和UI代码耦合在一起. 实践是类似的, 角度不同.
新实践: 关注对基础类型的操作.
频繁操作基础类型, 尤其在不同的场合以同样的方式来操作基础类型, 通常意味着领域概念的缺失. 比如字符串类型. 如果你发现经常需要取字符串的某一段或者定位某个特定子串, 则很可能是把领域概念编码在作为实现的字符串身上了. 事实上, 除了在输入输出或者Context的边界交换数据时, 不应该有任何字符串的操作.
另一个例子跟我司面试题有关, 计算金额时的舍入. 如果舍入是某种会计规则所明确要求的, 则应该对其显式建模, 而不是直接在计算时用些round()函数来隐式的表达.
Working on more practice...
分享到:
相关推荐
MDA Explained: The Practice and Promise of the Model Driven Architecture
Programming: Principles and Practice Using C++ 第二版 Bjarne Stroustrup epub版
Code Craft: The Practice of Writing Excellent Code 英文原版,带书签,清晰可复制
Cloud Computing: Theory and Practice provides students and IT professionals with an in-depth analysis of the cloud from the ground up. Beginning with a discussion of parallel computing and ...
First Edition by William Stallings and Lawrie Brown Lecture slides by Lawrie Brown
Business analysis For Practitioners Practice Guide
卡尔曼滤波理论与应用(Matlab版),非常经典,非常实用!
Computer Network Security Theory Practice PPT 计算机网络安全的理论与实践 中文PPT和英文PPT
This book presents modern JavaScript best practice, utilizing the features now available in the language that enable you to write more powerful code that is clean, performant, maintainable, and ...
3D UI 经典理论书籍 最新版 3D User Interfaces: Theory and Practice, 2nd Edition
Bjarne Stroustrup, "Programming: Principles and Practice Using C++"Addison-Wesley Professional | 2008 | ISBN: 0321543726 | 1272 pages | PDF | 129 MBAn Introduction to Programming by the Inventor of ...
国外多所大学最新采用教材,比mos更适合教学与自学
Kalman Filtering: Theory and Practice Using MATLAB, Fourth Edition is an ideal textbook in advanced undergraduate and beginning graduate courses in stochastic processes and Kalman filtering....
第一章:一个简单的通信游戏 第二章:防守与攻击 第三章:概率论和信息论 第四章:计算复杂性 第五章:代数基础 第六章:数论 第七章:加密-对称技术 第八章:加密-非对称技术 ...第十章:数据完整性技术 ...
world problems in practice as illustrative examples, and also covers the more practical aspects of implementation. The author Grewal teaches at Cal State Fullerton and also offers seminars and ...
美国伯克利,卡内基梅隆等高校都在用这本教材,很值得参考。
Rob J Hyndman and George Athanasopoulos Monash University, Australia 预测:原理与实践, 时间序列分析入门教材 浏览器版本: https://otexts.com/fpp2/
Graphics Shaders: Theory and Practice is intended for a second course in computer graphics at the undergraduate or graduate level, introducing shader programming in general, but focusing on the GLSL ...
Wireless Positioning:Principles and Practice 2019 Wireless Positioning:Principles and Practice 2019.zip (11.41 MB, 下载次数: 478 ) 收藏收
英国帝国理工,D J Ewins 教授关于模态测试的经典之作。前两章讲模态理论,接着讲数据采集,模态参数估计。振动专业学生必读。