From d5de65fdb1802cdf498d65d93397f290813c377c Mon Sep 17 00:00:00 2001 From: muqiuhan Date: Tue, 9 Sep 2025 06:17:00 +0000 Subject: deploy: 9665097f0fa0dae9f92123fac54d26c0818758a5 --- .../03/14/DDD-\344\270\255\347\232\204-Ubiquitous-Languages/index.html" | 1 - 1 file changed, 1 deletion(-) (limited to '2025/03/14/DDD-中的-Ubiquitous-Languages/index.html') diff --git "a/2025/03/14/DDD-\344\270\255\347\232\204-Ubiquitous-Languages/index.html" "b/2025/03/14/DDD-\344\270\255\347\232\204-Ubiquitous-Languages/index.html" index 3f99a42a..d72575f9 100644 --- "a/2025/03/14/DDD-\344\270\255\347\232\204-Ubiquitous-Languages/index.html" +++ "b/2025/03/14/DDD-\344\270\255\347\232\204-Ubiquitous-Languages/index.html" @@ -209,7 +209,6 @@

假设正在开发一个电子商务系统,业务专家使用“订单”来描述用户购买的商品集合。团队可以在代码中使用“Order”来命名相关的类和方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
type Order = {
items: OrderItem list
customer: Customer
orderDate: DateTime
}

type OrderItem = {
product: Product
quantity: int
}

type Customer = {
name: string
}

type Product = {
name: string
price: float
}

let addItem (order: Order) (item: OrderItem) =
{ order with items = order.items @ [item] }

let getTotalAmount (order: Order) =
let total = 0.0
for item in order.items do
total <- total + item.price
total

let getPrice (item: OrderItem) =
item.product.price * item.quantity

let getTotalPrice (order: Order) =
let total = 0.0
for item in order.items do
total <- total + getPrice(item)
total
-

在这个示例中使用了“Order”、“OrderItem”、“Customer”和“Product”等术语,这些术语都是 Ubiquitous Language 的一部分,可以提高代码与业务需求的一致性。

-- cgit v1.2.3