Brief introduction to domain-driven design


Published on

Published in: Technology
1 Comment
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 软件截图来自网络
  • 电影截图来自网络
  • Brief introduction to domain-driven design

    1. 1. Brief Introduction to Domain Driven Design(DDD) Yongqiang
    2. 2. Outline What’s Domain? What’s the heart of a software? What’s DDD? Crunching Knowledge Ubiquitous Language Basic Elements in DDD Summary References
    3. 3. What’s Domain? 在 DDD 中所指就是企业软件所涉及 Domain 的业务领域,其中包含大量业务知识。
    4. 4. What’s the heart of a software? 导演-> 软件用户 剪辑师 -> 软件工程师 剪辑师为什么没有解决导演的 问题?
    5. 5.  Theheart of software is its ability to solve domain-related problems for its users! ( 软 件的核心价值是为客户解决业务问题)。 如果想做出色的业务软件,前提就是对用 户所处的领域有充分的,全面的,深刻的 理解!
    6. 6. What’s DDD? 领域驱动开发 Evans 创始人 Eric 目标:让软件成为领域的映射。  软件需要具现领域里重要的核心概念和元素,并精 确实现它们之间的关系。  软件需要对领域进行建模,得到一个关于领域的 模型。 中心内容:如何将业务领域概念映射到软件工 件中
    7. 7. Crunching Knowledge( 知识汲取) Talk with domain expert Lead by developers Domain model is focused on the most valuable part Developer needs feedback We never know enough We need knowledge-rich design Binding model and implementation
    8. 8. Ubiquitous Language( 通用语言) For each term, we need a very precisely and unambiguously defined meaning spanning from discussions with the domain expert to the code level assures that everybody in the team shares the same vision about the domain and the software.
    9. 9. So... Modelingout loud! One Team, One Language!
    10. 10. Basic Elements in DDD
    11. 11. Layered Architecture
    12. 12. Entity An object define primarily by its identity is called an Entity. Most basic responsibility of Entities is to establish continuity so that behavior can be clear and predictable. class Person CD BankAccount - AccountId - Deposit - UserName
    13. 13.  Attributes VS. Identity class Person CD Person - BirthDate - BirthPlace - Id - Name - Parents
    14. 14. Value Object( 值对象 ) An object that represents a descriptive aspect of the domain with no conceptual identity is called a VALUE OBJECT. VALUE OBJECTS are often passed as parameters in messages between objects. class Person CD class Person CD Point Address - X: int - City - Y: int - Street
    15. 15.  帮助简化设计 没有标识符,值 对象可以被轻易 地创建或者丢弃 。 极力推荐值对象 是不变的。
    16. 16. Service( 服务 ) Some of these are intrinsically activities or actions, not things. A service tends to be named for an activity, rather that an entity-a verb rather that a noun. A service does not do much on its own; it would ask other objects to do most of work.
    17. 17.  Partition Services into Layers  Application  Domain  Infrastructure
    18. 18. Life Cycle of Domain Object Aggregates 聚合  用于打破对象的网状关系 , 定义所有权和边界 Factories 工厂  用于领域对象生命周期的开始部分 , 创建或者重组 复杂的对象或 Aggregates. Repositories 资源库  用于领域对象生命周期的中后部 , 对存储 , 检索查 询等功能进行了封装 .
    19. 19. Aggregate( 聚合 ) An aggregate is a cluster of associated objects that we treat as a unit for the purpose of data changes. Each aggregate has a root of a boundary. The root is the only member of the Aggregate that outside objects are allowed to hold references.
    20. 20.  Invariants, which are consistency rules that must be maintained whenever data changes.
    21. 21. Factory( 工厂 ) Creation of an object can be a major operation in itself, but complex assembly operations do not fit the responsibility of the created objects. Combining such responsibilities can produce ungainly designs that are hard to understand. A program element whose responsibility is the creation of other objects is called a FACTORY.
    22. 22.  Two basic requirements for any good Factory are  Each creation method is atomic and enforces all invariants of the created object or AGGREGATE.  The FACTORY should be abstracted to the type desired, rather than the concrete class(es) created.
    23. 23. Repositories( 资源库 ) Global Access  Aggregate roots which are not convenient to reach by traversal.  Value Objects with complex internal structure.  enumerated values. Two ways to query a repository  Hard-coded query with specific parameter.  Specification-based query.
    24. 24. By specific parameterBy criteria
    25. 25. Summary DDD 目标是建立最适合的模型映射领域知识 ,以模型做为团队交流和软件开发的基础。 DDD 对企业应用软件中的基础元素做了合理 的抽象。 DDD 可以和 TDD, 敏捷开发方法联合使用。
    26. 26. References EricEvans 《领域驱动设计—软件核心复杂 性应对之道》 InfoQ 《领域驱动设计精简版》