DDD在旅游电商架构演进中的实践
如果无法正常显示,请先停止浏览器的去广告插件。
1. DDD
2. CONTENTS
01
02
03
DDD
3.
4. BDD
Layered architecture
Layered Architecture
Monoliths
MicroKernel
Hexagonal Architecture
Modular monoliths
Microkernel
EDA
X
Onion Architecture
Service-based architectures
Screaming Architecture
SOA
MVC
Microservices
FP
George Fairbanks Pattern-oriented Software Architecture
5. +
6. VS
VS
D
D
D
7. VS
-
+
…
…
+
…
…
Software reuse is more like an organ transplant than snapping together Lego blocks.
—John D. Cook
8. VS
-
<<inclu
de>>
<<inclu
<<
<<i
>
inc
e>
>
n cl
ude
>>
<<
inc
lud
e>
lud
de>>
<<in
cl
<<in
ude
clud
e>>
>>
<<in
<<include>>
clud
e>>
<<include>>
>
<<include>>
in
<<
d
clu
>
e>
ds>
e>
>>
tends
<<ex
xten
lud
>>
<<e
<<
inc
clude
>
<<include>>
<<in
9. VS
-
…
…
10. CONTENTS
01
02
03
DDD
11. +
+
• 购买 • 预约 • 零售
• 预订
• 团购 • 预售 • 代理
• 自营
• 拼团
特产
• …
• 分销
• 单品 • 搭售
• 预打死包 • 购物车
• 预打半活包 • …
• 活包
• 门票
• 跟团
• 酒景
• 机酒
• 旅游用车
• 演出
• 特产
• …
12. -
1 -
•
•
+
•
•
•
13. -
1 -
-
cl u
<<in
>
de>
<<in
<<inclu
clud
e>>
de>>
lud
inc
<<
<<include>>
>
e>
<<inclu
<<inclu
de>>
de>>
<<include>>
in
<<
<<i
n cl
ude
lu
inc
<<
>>
d
clu
>
e>
>>
de
c
<<in
>
lude>
<<inc
<<in
u
ncl
<<i
clude
lude
>>
>>
<<ex
tends
>
>
>
de>
cl
<<in
ude
>>
14. 1 -
-
in
cl
<<
ud
e>
inc
>
lud
e>
>
-
lude
<<
c
<<in
>>
<<include>>
<<includ
<<in
<<
inc
lud
<<
ex
ten
clud
e>>
e>>
e>
>
…
ds
>>
<<include>>
<<
inc
lud
e>
>
…
…
15. -
1 -
e
clud
<<in
-
>>
<<in
<<include>>
>
<<include>
<<include
>>
cl u d
<
e>>
<<inclu
de>>
<<include>>
lud
inc
<<
i
<<
lu
nc
de
>>
>
e>
<<in
<<include>>
>>
lude
lud
c
<in
<<include>>
<<in
clud
c
ten
ex
<<
<<include>>
>>
ds
lud
inc
<<
>
e>
<<include>>
<<in
>>
ds
te
n
ex
e>>
<<
clud
<<include>>
>
e>
e>>
16. -
1 -
-
•
•
• • • •
• • • •
+
•
•
•
•
•
•
•
17. -
1 -
-
1
2
3
4
…
18. -
1 -
-
1
1
*
*
*
1
1
1
*
1
1 1
* *
1
1
1
1
*
*
1
*
*
1
*
1
*
*
1
1
19. -
1 -
-
•
•
+
+
• • • •
• • • •
• • •
• • •
• • • …
•
•
•
•
•
•
•
20. -
1
1 -
-
2
3
21. -
1 -
•
•
Enforce linguistic boundaries to protect the validity of a domain term.
+
Linguistic boundaries are bounded context boundaries.
•
•
2PTS
business capabilities are often strong indicators of linguistic boundaries
•
2PTS
from Millett S., Tune N.
- Patterns, Principles, and Practices of Domain-Driven Design
•
from
-
22. -
1 -
-
+
+
Product
+
+
23. -
1 -
-
Product
Product
Product
Product
24. -
1 -
-
•
•
• • • •
• • • •
• • •
• • •
• • • …
+
+
•
•
•
• • •
• • •
• • …
25. -
2 -
1
2
/
26. -
2 -
•
•
•
+
•
•
-
27. e>
ud
cl
in
<<
ncl
<<i
ud
incl
e>>
<<
>
<<include>>
<<
<<
in
cl u
de
inc
>>
lud
>
e>
ud
cl
in
<<
<<
in
cl
ud
e>
e>
>
<<in
clud
e>>
<<i
de>>
<<inclu
ude
>
>>
cl u d
ncl
e>>
ude
<<include
lud
<<in
e>
>
-
>>
>>
<<
inc
2 -
<<include>>
-
<<
lu
inc
de
>>
<<i
ncl
ude
>>
<<include>>
>
<<
inc
lud
e>>
>
e>
lud
inc
<<
<<include>>
c
in
<
<
>
de
lu
lude>
>
<<include>>
<<
lud
inc
>
e>
<<include>>
>>
ude
l
c
n
<<i
<<inc
…
28. -
2 -
<<i
ud
ncl
-
e>>
<<inclu
de>>
<<
<<include>>
<<
<<
inc
lud
inc
lud
e>
>
de
<<inclu
e>
>
n
<<i
clud
<<in
e >>
clud
inc
lud
e>
>
e >>
>>
<<include
>>
>
e>
clu
<<in
de>>
<<extends>>
de>>
<<ex
tends
>
>
lud
inc
<<
clu
<<in
de>>
e>>
>
e>
<<include
>>
<<inclu
<<inclu
lud
<<
in
<<
inc
clu
<<inclu
de
>>
in
<<
d
clu
de>>
ude
n cl
<<i
>
e>
e>>
in
<<
d
clu
clud
>>
<<in
<<include>>
de>>
<<include>>
<
cl
<i n
ud
>
e>
29. -
2 -
-
…
30. -
2 -
-
31. -
2 -
U
D
U
D
U
D
D
D
D
D
U
U
U
D
D
U
U
U
U
U
D
D
U
D
U
D
D
D
D
U
U
D
D
U
D
U
D
U
U
32. -
-
<<
in
cl
ud
e>
ude
ncl
<<i
2 -
>
>>
-
<<in
clud
e>>
<<include>>
<<
<<
in
…
❌
cl u
de
inc
lud
e>
>
>>
…
…
33. -
2 -
-
U
D
U
D
U
D
D
D
D
D
D
U
U
U
U
D
U
U
U
U
D
D
D
U
D
D
D
U
U
D
U
U
D
D
U
D
U
U
34. -
2 -
-
D
D
U
U
U
D
D
D
D
D
D
U
U
U
U
D
U
U
U
U
D
D
D
D
D
D
U
U
D
U
D
D
D
U
D
U
U
U
U
D
U
D
D
U
U
D
U
D
D
D
U U
U U
35. -
2 -
•
•
•
+
• • •
• • •
• • •
• • •
• • •
• • •
• • • •
• • • •
1
• …
• …
2
36. CONTENTS
01
02
03
DDD
37. t
x
e
t
Con
d
e
Architecture
d
n
u
o
B
e
l
u
d
o
Probl
M
Domain
em S
pace
service
Solution Space
m
Mic
u
t
n
ro S
a
u
Design
Pattern
ervi
Q
Compo
ce tural
nent
c
e
t
i
library
h
Archite
c
r
A
ctural P
attern
Architectural Style
38. Application architecture
Component
Module
Code
Bounded Context
Architectural Quantum
library
MicroService
service
— from Building evolutionary architecture
Architectural Granularity
Architectural Style
Layered architecture monoliths
Integration architecture
Modular monoliths
Service-based architectures
Microservices
39. -
Maintainability
SRP
LSP
OCP
Deployability
CCP
OO
ADP
Reusability
Maintainability
SDP
REP
DIP
ISP
Robert C. Martin
Extensibility
CRP
Deployability
SAP
Agile Software Development, Principles, Patterns, and Practices, First Edition Package Principles
Clean Architecture A Craftsman's Guide to Software Structure and Design Component Principles
40. Dr
ivi
ng
Fo
rc
e
-
Gro
u
r m
ain
ten
a
ou
Gr
SRP
p fo
nce
or
p f
CCP
ADP
reu
s
ser
OCP
LSP
o
Av
OO
SDP
id
REP
un
ne
ed
ed
re
le
es
ISP
as
DIP
CRP
SAP
41. -
Eric Evans
Robert C. Martin
Policy
Detail
Communication Protocols DB
IO
Frameworks
Messaging Transaction Persistence
42. -
1
Client
-
2 3 Client Client Client
User Interface Layer User Interface Layer
Application Layer
4
Application
Application Layer
Application Layer
Middle Layer
DIP
Third Party API
Middle Layer Middle Layer
Third Party API Third Party API
Third Party API
43. -
-
4
6
5
Client
Client Client
User Interface Layer User Interface Layer
Application Layer
DIP
Application Layer
Application Layer
DIP
Infrastructure Layer
User Interface Layer
DIP
DIP
DIP
Infrastructure Layer
Domain Layer
DIP
Infrastructure Layer
Third Party API
Third Party API
Third Party API
44. -
Client
Client
Client
Adapter
Adapter
Application
User Interface Layer
+DIP
Domain
- Alistair Cockburn
Adapter
Third Party API
Application Layer
Adapter
- Vaughn Vernon
Third Party API
es
Domain Layer
vic
De
Use Cases
en
ter
es
Pr
DB
ay
ew
t
Ga
Third Party API
s
Entities
s
External Interfaces
UI
Infrastructure Layer
W
eb
Controllers
- Robert C. Martin
45. -
-
Client
Client
Client
Adapter
Adapter
Application
User Interface Layer
- Alistair Cockburn
Adapter
Application Layer
- Vaughn Vernon
- Eric Evans
Third Party API
Adapter
Third Party API
Policy
- Robert C. Martin
es
Domain Layer
vic
en
ter
s
External Interfaces
UI
DB
ay
ew
t
Ga
Third Party API
es
Entities
s
Use Cases
Pr
Infrastructure Layer
W
eb
Controllers
De
+DIP
Domain
- Robert C. Martin
46. -
-
Client
SRP
User Interface Layer
Application Layer
Domain Layer
Infrastructure Layer
Third Party API
LSP
OCP
DIP
Separation of Concerns: separate changes at different rates, for different reasons.
The Axis of Change responsible for the creation of Architectural Boundaries.
Build Software systems from interchangeable parts.
Protect Policy from changes in Details
Protect Client from changes in Domain
Policy depend on Detail → Detail Depend on Policy
47.