当前位置:网站首页>Landing DDD (7) - some misunderstandings in tactical design
Landing DDD (7) - some misunderstandings in tactical design
2022-07-18 11:02:00 【xuhss_ com】
High quality resource sharing
| Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
|---|---|---|
| 🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
| Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |
background
I summed up a few years ago DDD Some landing experience of tactical design It's landing DDD(5)- Tactical design , and A heated discussion about aggregate roots There have been some new landing experiences in the past two years , Look back and find out , The original understanding of these concepts is still not in-depth , This article reinterprets .
There are some points that I didn't understand well before
- Each module of tactical design is a collaborative relationship
- What are problem space problems , What is the boundary of the scheme space problem is not clearly divided .
- The difference between entity and aggregation root is not well understood , Entity and aggregation root modeling methods are wrong .
The above questions will be explained clearly below .
Tactical design disassembly
DDD The tactical design of is to design the domain model of a certain sub domain and code landing . Field events 、 Domain object 、 Aggregate root 、 Entity 、 The value object 、 Field service 、 factory 、 These concepts such as resource pool belong to this category .
The author reassembles these concepts in layers , As shown in the figure below .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-38iZWLzF-1657860808612)(https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/78524dba9fad4d38b77f13a1e7251e7c~tplv-k3u1fbpfcp-watermark.image?)]
First, divide the whole into two parts , Problem space and solution space .
- Problem space is domain modeling . It is a description of business problems , And how we abstract these problems . These are needed in business 、 product 、 Development must be agreed , It has nothing to do with the specific technical scheme .
- Solution space is how to use technical means to solve problems , It is related to the realization of specific technology .
Problem space is domain modeling , Through entities 、 The value object 、 Field service 、 Domain events .
- Entity and value objects are model objects , Entity is the top priority , Including core model data 、 Behavior 、 state . The reason to distinguish between entities and value objects , To reduce complexity , Because the value object is a constant object , It doesn't take much energy .
Note that an object is a value object in a field , In another field, it may be an entity , So get out of the domain context , Say an object is a value object , It must be wrong , For example, we often say that the address is a value object , Must this be right ? - Domain events are events generated by entities
- Domain services include some logical calculations , And business strategy . For example, business decision logic 、 Business process, etc .
Solution space is how to solve problems , Realize the mapping between domain model and code . Realize the consistency between design and implementation . Mainly through factories , polymerization , Resource base to express .
- Aggregation is about entities 、 Encapsulation of value objects . All access to domain objects outside the domain is based on aggregation . For example, the infrastructure layer operates aggregation to save data . Other domains reference aggregate object data .
The design of aggregation generally revolves around technology , For example, aggregate object transaction . - factory , Complex object creation factory class
- The repository , Operations on aggregation .
From the perspective of the author's practice , to ground DDD In the process , Problem space is more important than solution space , The benefits are greater . Because usually some of the code we roast about is poorly written , Anemia model . It's not because it's useless DDD, But the problem space is not well defined , Have no deep understanding of business , This leads to insufficient model abstraction .
How to model
Why modeling
Usually landing in a certain sub domain DDD, We will analyze according to business -》 Use case analysis -》 Domain modeling ( Problem space ) -》 Technical landing ( Solution space ) These steps operate . But in fact, even if we don't land in the code DDD, Just use the front 3 Maintaining a domain model in a sub domain can also bring a lot of benefits , Including but not limited to
- Unify the cognition of each role of the business group , Business 、 product 、 Develop everyone's understanding of the same concept is consistent .
- Guide the splitting of development work .
For example, there is a bloody lesson in Taobao , So far, this historical debt cannot be repaired . Early in Taobao shop . A seller can only open one store . Sellers and stores are objects in two fields , The relationship is 1:1. The service of the store is 1:1 The relationship between , The services provided externally are well founded sellerId Get store information , So other callers unconsciously quoted the seller directly id, In this way, you can also get to the store . Lead to shopId Is equivalent to sellerID. This misquotation occurred in thousands of places , Finally, the subsequent need to support a seller to open multiple stores cannot support . Only through other trick How to achieve .
As previously introduced CRM field To explain .
Omit business analysis , Get the use case directly .
Use case analysis
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-2BDMnzxs-1657860808617)(https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f051a4755f06412b8899c6a77d14c795~tplv-k3u1fbpfcp-watermark.image?)]
List all use cases by user role , Used to derive the model 、 And the relationship between models . The domain model is established , You need to go through the listed use cases , Make sure that all use cases work . Only a complete set of use cases can derive the correct model , So when there is a change , First adjust the use case set , Then modify the domain model
modeling
Domain modeling is to define model objects , And the relationship between model objects . Modeling in two steps , The first step is to find the model object through nouns . The second step is to pass the verb 、 Adjective analysis object relevance
Noun
Usually, the nouns in the subject and object that appear repeatedly are the model objects , For example, marketing personnel create an activity , An activity is a model object . Of course, nouns appearing in attributives may also be model objects .
1. The definition of nouns must be clear . for instance crm There is a common term in the field called business opportunity . But your product manager is not familiar with crm field , Created a new word , Then you should correct him as soon as possible .
2. The meaning of a noun is semantically unique within the bounded context , The concept is not necessarily the same in different contexts . For example, activities created by marketing personnel , And the activities created during marketing are not necessarily .
Verb 、 Activities
1 One marketing person can create multiple activities , Therefore, the relationship between marketing personnel and activities is 1 For more than . The two exist independently , General relationship .
In order to simplify the description , Only market activities are listed 、 clue 、 Customer 、 Business opportunity these fields . user 、 role 、 jurisdiction 、 Data analysis these fields are ignored first .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-lWiGjkKe-1657860808618)(https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/31626ae62ae241d6be7d6d570b6da601~tplv-k3u1fbpfcp-watermark.image?)]
Output
In the process of derivation , We derive it from the bottom up , Finally, we present the results in the following way
- Domain terms
Marketing activities : Marketing personnel in order to show the company's image 、 Promote the company's products , Activities held to get clues . Multiple clues can be created in one activity .
clue : Salespeople explore potential customers based on clues , Multiple leads turn into one customer . Clues can be generated by a market activity , Or other channels .
Customer : Users who are interested in buying the company's products , Salesperson can follow up with customers , Transform sales opportunities .
Opportunities : Higher quality clues , Have the opportunity to sign the bill . You can get , It can also be obtained through other channels
- Domain model
Pictured above - Main fields state transition .
Because the complex domain object life cycle and some cross domain object interactions cannot be expressed in the domain model diagram , So we need to express with the help of additional graphs .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-abQggXbu-1657860808619)(https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8a83f4fc30e8465588e1a9fdad5d438a~tplv-k3u1fbpfcp-watermark.image?)]
边栏推荐
猜你喜欢
随机推荐
2022数学建模“五一杯”B题
Issue record: “No thread for socket” about Memcached
Five reasons why developers use helix QAC to achieve static code test compliance
C 语言基础双指针移除元素解法
Typora This beta version of Typora is expired, please download and install a newer version.最新解决方案
架构师进阶,微服务设计与治理的 16 条常用原则
There is only one day left to prepare for the examination of Guangxi Second Construction Engineering Co., Ltd. the first three pages of the examination of second-class cost engineer came and raised sc
【vulnhub】FIVE86: 1
11 digits of mobile phone number and format verification rules
编程语言学习和使用的观点
正大期货目前开预留4的主账户需要什么条件?信息面
(手工)【sqli-labs44、45】POST字符型注入、盲注、堆叠注入
Ten minute quick learning flash framework
Advanced architects, 16 common principles of microservice design and Governance
记录一次坑爹内存泄漏排查经历
以太网开发与测试,这一步你做对了吗 (1)
PHP版本新特性摘选 - PHP7.2.x 到 PHP7.4.x
交通灯 单片机课程设计
实验五 图像分割与描述
C语言 sizeof 和strlen 的用法和区别








