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
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.
So... Modelingout loud! One Team, One Language!
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
Attributes VS. Identity class Person CD Person - BirthDate - BirthPlace - Id - Name - Parents
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
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.
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.
Invariants, which are consistency rules that must be maintained whenever data changes.
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.
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.
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.