Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DDD 拼圖中的另一半 – 以戰術實踐代碼

在軟體開發過程中,時常會面臨許多複雜的需求場景,而這特別容易發生在企業的應用下。然而過往數據導向的直線式設計開發,卻容易使我們未發現、忽略建模時中所淺藏的需求複雜性,進而使得後期開發與重構難度提高。

為了解決這個現象,領域驅動設計 (DDD) 誕生了,藉由分析需求並建立領域的知識,以領域思維設計模型,使模型本身可以對焦業務並加以控制。因此 DDD 透過名為戰略建模的模式、事件風暴 (Event Storming)  來方法來實施。不過身為工程師的朋友肯定會有另一個疑問,那要實踐到開發中呢?

為解決這個議題 DDD 透過另一半的拼圖 - 戰術建模來達成。而在這次的分享將會簡介一下 DDD 戰術建模的 10 個實踐模式,讓各位有的初步的認識。

  • Login to see the comments

DDD 拼圖中的另一半 – 以戰術實踐代碼

  1. 1. DDD DDD 2020/10 DDDTW Meetup Eason Kuo
  2. 2. DDD
  3. 3. DDD
  4. 4. • • • DDD
  5. 5. DDD
  6. 6. DDD DDD DDD 2003 Eric Evans Domain-Driven Design
  7. 7. DDD ? - - DDD
  8. 8. DDD ? ? DDD -
  9. 9. Strategic Modeling
  10. 10. DDD • • • • • Strategic Modeling •
  11. 11. DDD
  12. 12. (1) ( Domain Storytelling - ( ) Strategic Modeling
  13. 13. (2) Event Storming () Strategic Modeling
  14. 14. Tactical Modeling
  15. 15. Tactical Modeling 1 0 69 ORM
  16. 16. Tactical Modeling
  17. 17. Tactical Modeling
  18. 18. A. ( C. B. ) Reason Tactical Modeling
  19. 19. A. C. B. ( ) 1. 2. (Service) Problem Reason 3. Tactical Modeling
  20. 20. A. C. B. ( ) 1. 2. (Service) Problem Reason 3. Tactical Modeling
  21. 21. Tactical Modeling • ( ) • ( )
  22. 22. DDD Tactical Modeling • • • • • • • • • • •
  23. 23. Architecture
  24. 24. DDD Tactical Modeling > (Architecture) • • • • •
  25. 25. Tactical Modeling > (Architecture) •
  26. 26. Tactical Modeling > (Architecture) • •
  27. 27. Tactical Modeling > (Architecture) (Onion Architecture), From 2008 • ( (Hexagonal Architecture), From 2005 Clean Architecture), From 2012 • (
  28. 28. Value Object
  29. 29. (Value Object) Tactical Modeling > (Value Object) ? Domain Driven Design - Tackling Complexity in the Heart of Software, Eric Evans
  30. 30. (Value Object) Tactical Modeling > (Value Object)
  31. 31. (Describe) (Measure) Tactical Modeling > (Value Object)
  32. 32. (Describe) (Measure) Tactical Modeling > (Value Object)
  33. 33. (Conceptual Whole) • • • • • Tactical Modeling > (Value Object)
  34. 34. (Conceptual Whole) ) ( Tactical Modeling > (Value Object)
  35. 35. ) ( Tactical Modeling > (Value Object)
  36. 36. - QA 100 - Tactical Modeling > (Value Object)
  37. 37. - - - Tactical Modeling > (Value Object)
  38. 38. = - Tactical Modeling > (Value Object)
  39. 39. - = Tactical Modeling > (Value Object)
  40. 40. • • - Tactical Modeling > (Value Object)
  41. 41. - - Tactical Modeling > (Value Object)
  42. 42. - Tactical Modeling > (Value Object) Setter Method (immutable) only getter
  43. 43. Tactical Modeling > (Value Object)
  44. 44. Tactical Modeling > (Value Object)
  45. 45. ) Side-Effect Free Tactical Modeling > (Value Object) ( ) (
  46. 46. Side-Effect Free Tactical Modeling > (Value Object) ( ) Method
  47. 47. Tactical Modeling > (Value Object) • • • •
  48. 48. (Entity) Entity
  49. 49. (Entity) ? Tactical Modeling > (Entity) Domain Driven Design - Tackling Complexity in the Heart of Software, Eric Evans
  50. 50. ID Ticket number Tactical Modeling > (Entity)
  51. 51. 1 30 Tactical Modeling > (Entity)
  52. 52. (Entity) 1. ) ( 3. ( ( Identity 2. e.g. Tactical Modeling > (Entity)
  53. 53. 0 vs 1 Tactical Modeling > (Entity)
  54. 54. 0 vs 1 Tactical Modeling > (Entity)
  55. 55. ID Tactical Modeling > (Entity)
  56. 56. ID • Tactical Modeling > (Entity) ID(int, string …) • • • •
  57. 57. • getter / setter • Tactical Modeling > (Entity) •
  58. 58. Tactical Modeling > (Entity) Table SchemaDomain Model
  59. 59. (Aggregate)
  60. 60. (Aggregate) ? Tactical Modeling > (Aggregate) Domain Driven Design - Tackling Complexity in the Heart of Software, Eric Evans
  61. 61. (Aggregate) ? Tactical Modeling > (Aggregate)
  62. 62. Tactical Modeling > (Aggregate)
  63. 63. Tactical Modeling > (Aggregate)
  64. 64. Tactical Modeling > (Aggregate) PS:
  65. 65. Tactical Modeling > (Aggregate) 3 ( ) 3 . 12 Bug .
  66. 66. 1 Tactical Modeling > (Aggregate) 4 3 2 Bug 3 3 ) . (
  67. 67. Tactical Modeling > (Aggregate) OrderItem Update Update Update
  68. 68. Tactical Modeling > (Aggregate) Order 250 Tracy Mary
  69. 69. Tactical Modeling > (Aggregate)
  70. 70. Tactical Modeling > (Aggregate) Order 250
  71. 71. Tactical Modeling > (Aggregate) Order ) 250 (
  72. 72. (Aggregate) Tactical Modeling > (Aggregate) •
  73. 73. (Aggregate) Tactical Modeling > (Aggregate) • (Entity) (Value Object)
  74. 74. (Aggregate) Tactical Modeling > (Aggregate) •
  75. 75. (Aggregate) ( Tactical Modeling > (Aggregate) • Business rule ) ( • • • 0 • • • x
  76. 76. (Aggregate) Tactical Modeling > (Aggregate) • • (Transaction)
  77. 77. (Aggregate) Tactical Modeling > (Aggregate) • (Aggregate Root) •
  78. 78. (Aggregate) Tactical Modeling > (Aggregate) • (Entity) • • • • •
  79. 79. (Aggregate) Tactical Modeling > (Aggregate) • (Entity) • • • • •
  80. 80. (Aggregate) Tactical Modeling > (Aggregate) • •
  81. 81. (Aggregate) Tactical Modeling > (Aggregate) • •
  82. 82. (Aggregate) ) ( Tactical Modeling > (Aggregate) •
  83. 83. (Aggregate) Tactical Modeling > (Aggregate)
  84. 84. (Aggregate) Tactical Modeling > (Aggregate) ID
  85. 85. (Factory)
  86. 86. (Factory) DDD Tactical Modeling > (Factory) •
  87. 87. Tactical Modeling > (Factory) • Factory Method Abstract Factory Builder • • Car altis = Car.StartToManufacture() v.s Car altis = Car.Create() Client Factory Car Aggregate Root Create manufacture car
  88. 88. Tactical Modeling > (Factory) • • • •
  89. 89. Tactical Modeling > (Factory) • • • • •
  90. 90. (Repository)
  91. 91. (Repository) Tactical Modeling > (Repository) • CRUD • • • (1:1 1: N)
  92. 92. (Repository) Tactical Modeling > (Repository) DDD
  93. 93. (Repository) ? Tactical Modeling > (Repository) Domain Driven Design - Tackling Complexity in the Heart of Software, Eric Evans
  94. 94. DDD (Repository) Tactical Modeling > (Repository) • • • • CRUD
  95. 95. Tactical Modeling > (Repository) • (1:1 1: N) ? • E.g : Order, OrderItem OrderRepository OrderItemRepository • Order OrderItem • OrderItem Order • OrderItem Order
  96. 96. Tactical Modeling > (Repository) • • • (1:1 1: N) ? • E.g : Order, OrderItem OrderRepository OrderItemRepository • Order OrderItem • OrderItem Order • OrderItem Order
  97. 97. Tactical Modeling > (Repository) • client Insert Update Delete Query Client
  98. 98. Tactical Modeling > (Repository) • • txt •
  99. 99. Tactical Modeling > (Repository) • • Application Service • Session Unit Of Work Commit
  100. 100. (Domain Service)
  101. 101. Tactical Modeling > (Domain Service) • A B A Account B Account •
  102. 102. Tactical Modeling > (Domain Service) • A B A Account B Account N’s Order Record • .
  103. 103. (Domain Service) Tactical Modeling > (Domain Service) • • • • • • •
  104. 104. (Domain Service) Tactical Modeling > (Domain Service) • • • • • •
  105. 105. (Domain Service) Tactical Modeling > (Domain Service) • ( Bounded Context • )
  106. 106. (Application Service)
  107. 107. (Application Service) Tactical Modeling > (Application Service) • Client Use Case) • • Client Input Output • • • • (
  108. 108. (Application Service) Tactical Modeling > (Application Service) • •
  109. 109. Tactical Modeling > (Application Service)
  110. 110. (Domain Event)
  111. 111. (Domain Event) Tactical Modeling > (Domain Event) Domain-Driven Design Reference - Definitions and Pattern Summaries, Eric Evans
  112. 112. (Domain Event) Tactical Modeling > (Domain Event) • • • Order Created • (Create Order) (Order Created)
  113. 113. (Domain Event) ? Tactical Modeling > (Domain Event) • • • • • •
  114. 114. (Domain Event) ? Tactical Modeling > (Domain Event) • • • • • • •
  115. 115. (Domain Event) Tactical Modeling > (Domain Event) • • •
  116. 116. (Domain Event) Tactical Modeling > (Domain Event) • (immutable) . • (primitive value) • metadata • ID
  117. 117. (Domain Event) - Tactical Modeling > (Domain Event) • •
  118. 118. (Module)
  119. 119. (Module) Tactical Modeling > (Module) •
  120. 120. . (Module) Tactical Modeling > (Module) • ) . . • • ) ( • . • app, controller, model, db, service
  121. 121. DDD (Module) Tactical Modeling > (Module) • • • (CCP) • •
  122. 122. DDD (Module) (1) Tactical Modeling > (Module) 1. 2. • • Bounded Context •
  123. 123. DDD (Module) (2) Tactical Modeling > (Module) 3. domain • models • services • repositories • factories 4. models • events • exceptions
  124. 124. Take Away Tactical Modeling > Take Away • DDD • DDD pattern language • • DDD •

×