領域驅動設計 (Domain Driven Design)

35
領領領領領領 K.NET 講講 Clark

Transcript of 領域驅動設計 (Domain Driven Design)

Page 1: 領域驅動設計 (Domain Driven Design)

領域驅動設計K.NET 講師 Clark

Page 2: 領域驅動設計 (Domain Driven Design)

Microsoft MVP 部落格:昏睡領域 http://www.dotblogs.com.tw/clark/ 技術專長:

◦ 領域驅動設計流程◦ 系統架構分析設計◦ 軟體框架分析設計◦ 軟韌硬體整合開發

關於我

Page 3: 領域驅動設計 (Domain Driven Design)

基礎知識 需求分析 系統分析 系統設計 系統實作 持續回饋

Agenda

Page 4: 領域驅動設計 (Domain Driven Design)

在各個開發階段,提供指引與方針軟體開發流程

系統分析 系統設計 系統實作

領域驅動設計

Page 5: 領域驅動設計 (Domain Driven Design)

透過分層設計,聚焦領域邏輯三層式架構設計

Presentation AccessesDomain

APP Server Database

Presentation

Domain

Presentation

Domain

Presentation

Domain

Accesses Accesses Accesses

Page 6: 領域驅動設計 (Domain Driven Design)

Channel9 課程連結:◦ https://channel9.msdn.com/Series/three-tier-design

點部落課程簡報:◦ https://dotblogs.com.tw/clark/2016/03/14/075524

三層式架構設計 – 課程資源

Page 7: 領域驅動設計 (Domain Driven Design)

基礎知識 需求分析 系統分析 系統設計 系統實作 持續回饋

Agenda

Page 8: 領域驅動設計 (Domain Driven Design)

軟體,是特定領域問題的解決方案軟體的用途

Page 9: 領域驅動設計 (Domain Driven Design)

找出需求背後的問題,提供解決方案服務的專業

需求 + 問題

Page 10: 領域驅動設計 (Domain Driven Design)

基礎知識 需求分析 系統分析 系統設計 系統實作 持續回饋

Agenda

Page 11: 領域驅動設計 (Domain Driven Design)

提供多元面向的解決方案網路拓樸

餐廳營運系統

Azure

門店點餐平板 門店營運伺服器

餐廳營運資料庫座位RFID掃描器

門店帶位前台

Page 12: 領域驅動設計 (Domain Driven Design)

釐清解決方案的使用情景使用案例

座位狀態顯示客戶入座功能

客戶餐點查詢

Timer帶位人員

自動座位安排

Page 13: 領域驅動設計 (Domain Driven Design)

釐清解決方案的操作流程Prototype

京站門店帶位前台

桌號:01座位:03/04

桌號:02座位:00/04

桌號:04座位:00/04

桌號:05座位:04/04

桌號:03座位:00/02

桌號:06座位:02/02

桌號:05小籠包x1臭豆腐x2蚵仔煎x6üü

使用中

空座位

自動座位安排

Page 14: 領域驅動設計 (Domain Driven Design)

釐清解決方案的功能需求功能清單工作項目 項目說明 優先順序座位狀態顯示 - 定時刷新目前座位狀態

- 座位狀態:入座數量、座位數量、入座狀態 - 入座狀態:空座位、使用中

客戶入座功能 - 確認客戶人數及座位後,即可安排客人入座 高客戶餐點查詢 - 帶位人員可查詢目前入座客戶的餐點訂單 低自動帶位功能 - 確認客戶人數後,系統自動計算座位安排

- 計算規則:入座空位最少、不提供併桌計算中

…… …… ………… …… ……

Page 15: 領域驅動設計 (Domain Driven Design)

釐清解決方案的領域概念領域模型

門店帶位前台

門店

座位

顧客

餐點訂單

1*

*1

*1

1*

Page 16: 領域驅動設計 (Domain Driven Design)

基礎知識 需求分析 系統分析 系統設計 系統實作 持續回饋

Agenda

Page 17: 領域驅動設計 (Domain Driven Design)

統一領域模型的英文詞彙詞彙表

中文名詞 英文名詞 備註門店 Store座位 Seat顧客 Customer餐點訂單 Meal Order…… …… ………… …… ………… …… ……

Page 18: 領域驅動設計 (Domain Driven Design)

套用詞彙表將領域模型轉為領域物件領域物件

門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

*1

1*

Page 19: 領域驅動設計 (Domain Driven Design)

劃分進出系統邊界的物件顆粒切割相依: Entity

門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

*1

1*

Page 20: 領域驅動設計 (Domain Driven Design)

劃分進出系統邊界的物件顆粒切割相依: Entity

門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

*1

+Id

+Id+Id

1*

Page 21: 領域驅動設計 (Domain Driven Design)

建立 Entity 物件進出系統邊界的物件門戶切割相依: Repository門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

*1

+Id

+Id+Id

1*

<<inteface>>CustomerRepository

<<inteface>>SeatRepository

<<inteface>>StoreRepository

Page 22: 領域驅動設計 (Domain Driven Design)

建立 Entity 物件進出系統邊界的物件門戶切割相依: Repository門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

*1

+Id

+Id+Id

1*

<<inteface>>CustomerRepository

<<inteface>>SeatRepository

<<inteface>>StoreRepository

Page 23: 領域驅動設計 (Domain Driven Design)

定義 Entity 物件之間的關聯切割相依: Association門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

*1

+Id

+Id+MealOrderList

+Id

<<inteface>>CustomerRepository

<<inteface>>SeatRepository

<<inteface>>StoreRepository

Page 24: 領域驅動設計 (Domain Driven Design)

定義 Entity 物件之間的關聯切割相依: Association門店帶位前台

Store

Seat

Customer

MealOrder

1*

*1

+Id+CustomerId

+Id+MealOrderList

+Id

<<inteface>>CustomerRepository

<<inteface>>SeatRepository

<<inteface>>StoreRepository

Page 25: 領域驅動設計 (Domain Driven Design)

定義 Entity 物件之間的關聯切割相依: Association

門店帶位前台

Store

Seat

Customer

MealOrder

+StoreId+Id+CustomerId

+StoreId+Id+MealOrderList

+Id

<<inteface>>CustomerRepository

+GetAllByStoreId(storeId)

<<inteface>>SeatRepository

+GetAllByStoreId(storeId)

<<inteface>>StoreRepository

Page 26: 領域驅動設計 (Domain Driven Design)

散落畫面欄位到 Entity

散落職責: Property門店帶位前台

Store

Seat

Customer

MealOrder+Name+Count

<<inteface>>CustomerRepository

+GetAllByStoreId(storeId)

<<inteface>>SeatRepository

+GetAllByStoreId(storeId)

<<inteface>>StoreRepository

+Id+Name

+StoreId+Id+Name+Count+State+CustomerId

+StoreId+Id+MealOrderList+Count

Page 27: 領域驅動設計 (Domain Driven Design)

散落畫面功能到 Entity 、 Repository

散落職責: Method門店帶位前台

Store

Seat

Customer

MealOrder+Name+Count

<<inteface>>CustomerRepository

+AddCustomer(customer)+GetAllByStoreId(storeId)

<<inteface>>SeatRepository

+SetSeat(seat)+GetAllByStoreId(storeId)

<<inteface>>StoreRepository

+GetCurrentStore()

+Id+Name

+StoreId+Id+Name+Count+State+CustomerId

+StoreId+Id+MealOrderList+Count

Page 28: 領域驅動設計 (Domain Driven Design)

散落畫面功能到 Service

散落職責: Service門店帶位前台

Store

Seat

Customer

MealOrder+Name+Count

<<inteface>>CustomerRepository

+AddCustomer(customer)+GetAllByStoreId(storeId)

<<inteface>>SeatRepository

+SetSeat(seat)+GetAllByStoreId(storeId)

<<inteface>>StoreRepository

+GetCurrentStore()

+Id+Name

+StoreId+Id+Name+Count+State+CustomerId

+StoreId+Id+MealOrderList+Count

SmartUsherService

+Usher(customer)

Page 29: 領域驅動設計 (Domain Driven Design)

描述功能職責,所進行的物件交互功能交互:順序圖

門店帶位前台 - 自動帶位功能

SmartUsherService SeatRepository CustomerRepository

Usher(customer)

GetAllByStoreId(storeId)

return seatList

Distribute(customer, seatList)

SetSeat(seat)

AddCustomer(customer)

return seat

Page 30: 領域驅動設計 (Domain Driven Design)

基礎知識 需求分析 系統分析 系統設計 系統實作 持續回饋

Agenda

Page 31: 領域驅動設計 (Domain Driven Design)

套用 Facade 模式,簡化操作使用封裝 Context

門店帶位前台

<<inteface>>CustomerRepository

+AddCustomer(customer)+GetAllByStoreId(storeId)

<<inteface>>SeatRepository

+SetSeat(seat)+GetAllByStoreId(storeId)

<<inteface>>StoreRepository

+GetCurrentStore()

SmartUsherService

+Usher(customer)

UsherContext+StoreRepository+SeatRepository+CustomerRepository+SmartUsherService

Page 32: 領域驅動設計 (Domain Driven Design)

選用 DI Framework ,填充 Context 內容注入 Context

門店帶位前台

<<inteface>>CustomerRepository

+AddCustomer(customer)+GetAllByStoreId(storeId)

<<inteface>>SeatRepository

+SetSeat(seat)+GetAllByStoreId(storeId)

<<inteface>>StoreRepository

+GetCurrentStore()

SmartUsherService

+Usher(customer)

UsherContext+StoreRepository+SeatRepository+CustomerRepository+SmartUsherService

DI Framework

SQLStoreRepository

SQLSeatRepository

SQLCustomerRepository

<<create>> <<create>> <<create>>

<<create>>

DI Framework

Page 33: 領域驅動設計 (Domain Driven Design)

基礎知識 需求分析 系統分析 系統設計 系統實作 持續回饋

Agenda

Page 34: 領域驅動設計 (Domain Driven Design)

持續回饋問題,完整封裝領域知識回饋模型

問題反饋

領域模型領域知識 領域物件

Page 35: 領域驅動設計 (Domain Driven Design)

Q & A領域驅動設計

K.NET 講師 Clark