具体描述
领域驱动设计(DDD)是教我们如何做好软件的,同时也是教我们如何更好地使用面向对象技术的。它为我们提供了设计软件的全新视角,同时也给开发者留下了一大难题:如何将领域驱动设计付诸实践?VaughnVernon的这本《实现领域驱动设计》为我们给出了全面的解答。《实现领域驱动设计英文版》分别从战略和战术层面详尽地讨论了如何实现DDD,其中包含了大量的优秀实践、设计准则和对一些问题的折中性讨论。《实现领域驱动设计英文版》共分为14章。DDD战略部分讲解了领域、限界上下文、上下文映射图和架构等内容;战术部分包括实体、值对象、领域服务、领域事件、聚合和资源库等内容。一个虚构的案例研究贯穿全书,这对于实例讲解DDD实现来说非常有用。《实现领域驱动设计英文版》在DDD的思想和实现之间建立起了一座桥梁,架构师和程序员均可阅读,同时也可以作为一本DDD参考书。
作者简介
Vaughn Vernon 是一个经验丰富的软件工程师,在软件设计、开发和架构方面拥有超过25年的从业经验。他提倡通过创新来简化软件的设计和实现。从20世纪80年代起,他便开始使用面向对象语言进行编程;在20世纪90年代早期,他便在领域建模中应用了领域驱动设计,那时他使用的是Smalltalk语言。他在很多业务领域都有从业经验,包括航空、环境、地理、保险、医学和电信等领域。同时,Vaughn在技术上也取得了很大的成功,包括开发可重用的框架和类库等。他在全球范围之内提供软件咨询和演讲,此外,他还在许多国家教授《实现领域驱动设计》的课程。你可以通过www.VaughnVernon.co访问到他的最新研究成果。他的Twitter:@VaughnVernon。
目录信息
前言
致谢
关于作者
如何使用本书、
Chapter 1 Getting Started with DDD
Can I DDD?
Why You Should Do DDD
How to Do DDD
The Business Value of Using DDD
1. The Organization Gains a Useful Model of Its Domain
2. A Refined, Precise Definition and Understanding of the Business Is Developed
3. Domain Experts Contribute to Software Design
4. A Better User Experience Is Gained
5. Clean Boundaries Are Placed around Pure Models
6. Enterprise Architecture Is Better Organized
7. Agile, Iterative, Continuous Modeling Is Used
8. New Tools, Both Strategic and Tactical, Are Employed
The Challenges of Applying DDD
Fiction, with Bucketfuls of Reality
Wrap-Up
Chapter 2 Domains, Subdomains, and Bounded Contexts
Big Picture
Subdomains and Bounded Contexts at Work
Focus on the Core Domain
Why Strategic Design Is So Incredibly Essential
Real-World Domains and Subdomains
Making Sense of Bounded Contexts
Room for More than the Model
Size of Bounded Contexts
Aligning with Technical Components
Sample Contexts
Collaboration Context.
Identity and Access Context.
Agile Project Management Context
Wrap-Up
Chapter 3 Context Maps
Why Context Maps Are So Essential
Drawing Context Maps
Projects and Organizational Relationships
Mapping the Three Contexts
Wrap-Up
Chapter 4 Architecture
Interviewing the Successful CIO
Layers
Dependency Inversion Principle
Hexagonal or Ports and Adapters
Service-Oriented
Representational State Transfer—REST
REST as an Architectural Style
Key Aspects of a RESTful HTTP Server
Key Aspects of a RESTful HTTP Client
REST and DDD
Why REST?
Command-Query Responsibility Segregation, or CQRS
Examining Areas of CQRS
Dealing with an Eventually Consistent Query Model
Event-Driven Architecture
Pipes and Filters
Long-Running Processes, aka Sagas
Event Sourcing
Data Fabric and Grid-Based Distributed Computing
Data Replication
Event-Driven Fabrics and Domain Events
Continuous Queries
Distributed Processing
Wrap-Up
Chapter 5 Entities
Why We Use Entities
Unique Identity.
User Provides Identity
Application Generates Identity
Persistence Mechanism Generates Identity
Another Bounded Context Assigns Identity
When the Timing of Identity Generation Matters
Surrogate Identity
Identity Stability.
Discovering Entities and Their Intrinsic Characteristics
Uncovering Entities and Properties
Digging for Essential Behavior
Roles and Responsibilities
Construction
Validation
Change Tracking
Wrap-Up
Chapter 6 Value Objects
Value Characteristics
Measures, Quantifies, or Describes
Immutable
Conceptual Whole
Replaceability
Value Equality.
Side-Effect-Free Behavior
Integrate with Minimalism.
Standard Types Expressed as Values
Testing Value Objects
Implementation.
Persisting Value Objects
Reject Undue Influence of Data Model Leakage.
ORM and Single Value Objects
ORM and Many Values Serialized into a Single Column
ORM and Many Values Backed by a Database Entity.
ORM and Many Values Backed by a Join Table.
ORM and Enum-as-State Objects
Wrap-Up
Chapter 7 Services
What a Domain Service Is (but First, What It Is Not)
Make Sure You Need a Service.
Modeling a Service in the Domain
Is Separated Interface a Necessity?
A Calculation Process
Transformation Services.
Using a Mini-Layer of Domain Services
Testing Services.
Wrap-Up
Chapter 8 Domain Events
The When and Why of Domain Events
Modeling Events
With Aggregate Characteristics
Identity
Publishing Events from the Domain Model
Publisher
Subscribers
Spreading the News to Remote Bounded Contexts
Messaging Infrastructure Consistency
Autonomous Services and Systems
Latency Tolerances
Event Store
Architectural Styles for Forwarding Stored Events
Publishing Notifications as RESTful Resources
Publishing Notifications through Messaging Middleware
Implementation
Publishing the NotificationLog
Publishing Message-Based Notifications
Wrap-Up
Chapter 9 Modules
Designing with Modules
Basic Module Naming Conventions
Module Naming Conventions for the Model.
Modules of the Agile Project Management Context
Modules in Other Layers
Module before Bounded Context
Wrap-Up
Chapter 10 Aggregates
Using Aggregates in the Scrum Core Domain
First Attempt: Large-Cluster Aggregate
Second Attempt: Multiple Aggregates
Rule: Model True Invariants in Consistency Boundaries
Rule: Design Small Aggregates
Don’t Trust Every Use Case
Rule: Reference Other Aggregates by Identity
Making Aggregates Work Together through Identity
References
Model Navigation
Scalability and Distribution
Rule: Use Eventual Consistency Outside the Boundary
Ask Whose Job It Is
Reasons to Break the Rules
Reason One: User Interface Convenience
Reason Two: Lack of Technical Mechanisms
Reason Three: Global Transactions
Reason Four: Query Performance
Adhering to the Rules
Gaining Insight through Discovery.
Rethinking the Design, Again
Estimating Aggregate Cost
Common Usage Scenarios
Memory Consumption
Exploring Another Alternative Design
Implementing Eventual Consistency.
Is It the Team Member’s Job?
Time for Decisions
Implementation
Create a Root Entity with Unique Identity
Favor Value Object Parts
Using Law of Demeter and Tell, Don’t Ask
Optimistic Concurrency.
Avoid Dependency Injection.
Wrap-Up
Chapter 11 Factories
Factories in the Domain Model
Factory Method on Aggregate Root
Creating CalendarEntry Instances
Creating Discussion Instances
Factory on Service
Wrap-Up
Chapter 12 Repositories
Collection-Oriented Repositories
Hibernate Implementation
Considerations for a TopLink Implementation
Persistence-Oriented Repositories
Coherence Implementation
MongoDB Implementation
Additional Behavior
Managing Transactions
A Warning
Type Hierarchies
Repository versus Data Access Object
Testing Repositories
Testing with In-Memory Implementations
Wrap-Up
Chapter 13 Integrating Bounded Contexts
Integration Basics
Distributed Systems Are Fundamentally Different
Exchanging Information across System Boundaries
Integration Using RESTful Resources
Implementing the RESTful Resource
Implementing the REST Client Using an Anticorruption Layer
Integration Using Messaging
Staying Informed about Product Owners and Team Members
Can You Handle the Responsibility?
Long-Running Processes, and Avoiding Responsibility
Process State Machines and Time-out Trackers
Designing a More Sophisticated Process
When Messaging or Your System Is Unavailable
Wrap-Up
Chapter 14 Application.
User Interface
Rendering Domain Objects
Render Data Transfer Object from Aggregate Instances
Use a Mediator to Publish Aggregate Internal State
Render Aggregate Instances from a Domain Payload Object
State Representations of Aggregate Instances
Use Case Optimal Repository Queries.
Dealing with Multiple, Disparate Clients
Rendition Adapters and Handling User Edits
Application Services
Sample Application Service
Decoupled Service Output
Composing Multiple Bounded Contexts
Infrastructure
Enterprise Component Containers
Wrap-Up
Appendix A Aggregates and Event Sourcing: A+ES
Inside an Application Service
Command Handlers
Lambda Syntax
Concurrency Control.
Structural Freedom with A+ES
Performance
Implementing an Event Store
Relational Persistence
BLOB Persistence
Focused Aggregates
Read Model Projections
Use with Aggregate Design
Events Enrichment
Supporting Tools and Patterns
Event Serializers
Event Immutability
Value Objects
Contract Generation
Unit Testing and Specifications
Event Sourcing in Functional Languages
Bibliography
Index
· · · · · · (收起)
读后感
用户评价
相较于市面上很多只关注“如何用某个框架实现DDD”的书籍,这本书的价值在于它的“普适性”和“永恒性”。它教授的是一套设计哲学和一套思考问题的方法论,而不是针对特定框架的快速入门指南。这意味着,无论未来出现了多么新颖的编程语言或框架,书中奠定的这些核心设计原则依然坚如磐石。我在阅读过程中,时不时会停下来,对照自己正在负责的项目,审视现有的模块划分是否合理,或者某个服务边界是否清晰。这本书的强大之处在于它能让你进行“深度自我反思”。它没有提供简单的复制粘贴的答案,而是提供了一套让你能够自己推导出最优解的工具箱。对于希望职业生涯能够从“实现功能”迈向“构建健壮、可演进的复杂系统”的工程师而言,这本书的阅读体验更像是一次思维的重塑和升级,它教会你的远不止是DDD的语法,而是如何以更系统、更具远见的方式去驾驭软件复杂性。读完之后,我感到自己对架构的理解更加稳固和成熟了。
这本书的语言风格有一种老派的严谨感,但又充满了对现代软件开发挑战的洞察力。它不像有些新锐的技术书籍那样追求花哨的时髦概念,而是沉稳地回归到设计的本质上去。在讨论DDD的核心概念时,作者总是能够将抽象的哲学思想,精准地锚定在具体的代码结构和设计决策上。例如,在讲解“实体”与“值对象”的区别时,它不仅仅是停留在理论层面,而是深入到了对象的唯一标识性、可变性对系统行为的影响,以及如何通过DDD的建模思想来自然地规避很多面向对象设计中常见的臭味代码。更值得一提的是,书中对“模型驱动”的强调,不仅仅是说“我们要建模”,而是详细阐述了如何通过持续的对话和迭代来深化模型,以及如何防止模型随着业务的变迁而僵化。这需要读者具备一定的思考深度和耐心,但一旦理解了这种思维方式,会发现自己看任何系统的眼光都会变得不一样,不再是仅仅关注技术实现细节,而是开始关注信息流和概念边界的清晰度。
说实话,当我翻开这本书时,最大的期待是能看到一些超越教科书定义的、更贴近实战的“陷阱”和“解药”。这本书在这方面做得相当出色。它没有避开那些在大型项目中经常遇到的灰色地带,比如“聚合根”的选择困难症,或者在微服务架构下如何处理跨限界上下文的事务问题。作者很坦诚地分享了自己在不同项目规模中踩过的坑,并且提供了几套行之有效的应对策略,这些策略不是简单的“应该这样做”,而是带有情境分析的——“在A情况下,B方案的优劣势是什么”。这种深入骨髓的实战经验的传递,是任何官方文档或基础教程都无法比拟的。我特别喜欢其中关于“防腐层(Anti-Corruption Layer)”的设计模式介绍,它不是简单地解释了ACL的定义,而是通过一个老旧遗留系统与新系统的对接案例,展示了ACL如何像一个智能的“翻译官”一样工作,既保护了新系统的纯洁性,又确保了必要的数据流通。对于那些正在进行系统重构或面对遗留系统整合的开发者来说,这部分的价值简直是无价的,它提供了一个清晰的、可执行的蓝图。
我个人觉得这本书的配套资源和索引设计非常人性化,这对于一本厚重的技术参考书来说至关重要。当你在实际工作中遇到一个具体问题,比如需要回顾“领域事件”的最佳实践时,可以迅速通过结构化的目录或详尽的索引找到对应的章节,里面的示例代码不仅干净,而且注释精炼到位,直接可以作为参考模板。有一点让我印象非常深刻,书中对于“架构边界”的讨论,没有仅仅局限于模块划分,而是上升到了组织结构(康威定律)的高度,阐述了DDD的成功实施往往需要组织架构的相应调整。这种跨学科的视角,让这本书的格局远超一般的编程指南。它强迫你思考:我们团队是如何组织的?我们的沟通机制是否阻碍了清晰的领域模型形成?这种对人与流程的关注,使得书中的技术建议更具可操作性和前瞻性,避免了技术方案脱离现实团队能力的尴尬境地。
这本书的封面设计实在是太吸引人了,那种深邃的蓝调和充满力量感的字体搭配,瞬间就让人感受到其中蕴含的专业和深度。拿到手里的时候,能明显感觉到纸张的质感,那种扎实的触感非常棒,说明出版方在细节上也下了不少功夫。我本来以为这会是一本读起来会比较枯燥的技术手册,但实际上,它的排版非常清晰,逻辑脉络也很顺畅。作者在讲解复杂的概念时,总能找到非常贴切的比喻,让原本抽象的DDD(领域驱动设计)原则变得生动起来,而不是一味地堆砌术语。特别是关于“限界上下文”的划分,书中提供了几个非常经典的案例分析,我感觉自己仿佛置身于一个真实的业务场景中,跟着设计者一起思考如何将混乱的需求梳理成清晰的软件结构。对于初学者来说,这本书就像一位耐心又经验丰富的导师,它没有急于让你掌握所有高级技巧,而是先把地基打牢。我尤其欣赏它对于“通用语言”的强调,这不仅仅是技术团队内部的沟通工具,更是连接业务和技术的桥梁,书中对此的论述深度和广度都让我印象深刻。读完前几章,我已经对如何更好地与产品经理、业务专家合作有了全新的认识,这不仅仅是一本关于代码架构的书,更是一本关于“如何更好地理解业务并用软件表达出来”的指南。