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
4. What’s the heart of a software?
导演-> 软件用户
剪辑师 -> 软件工程师
剪辑师为什么没有解决导演的
问题?
5. Theheart of software is its ability to solve
domain-related problems for its users! ( 软
件的核心价值是为客户解决业务问题)。
如果想做出色的业务软件,前提就是对用
户所处的领域有充分的,全面的,深刻的
理解!
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. 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.
15. 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
16. Attributes VS. Identity
class Person CD
Person
- BirthDate
- BirthPlace
- Id
- Name
- Parents
17. 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
19. 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.
24. 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.
25.
26. Invariants,
which are consistency rules that
must be maintained whenever data changes.
27. 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.
28. 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.
29.
30. 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.