0
00:00:00,740 --> 00:00:02,200
那刚才讲了
1
00:00:02,480 --> 00:00:04,211
Evans这个隐喻
2
00:00:04,211 --> 00:00:06,520
实际上背后是把集合
3
00:00:06,800 --> 00:00:08,560
当成了聚合
4
00:00:10,580 --> 00:00:14,350
那为什么有这样的一个隐喻,根源在哪里
5
00:00:14,710 --> 00:00:16,960
根源可能是来自于
6
00:00:17,570 --> 00:00:20,790
Aggregate这个词
7
00:00:21,310 --> 00:00:23,860
之前是用在哪里
8
00:00:25,540 --> 00:00:25,815
9
00:00:25,815 --> 00:00:27,470
之前是用在
10
00:00:27,750 --> 00:00:29,570
统计上面
11
00:00:29,570 --> 00:00:31,693
比如说,Excel里面
12
00:00:31,693 --> 00:00:33,513
SQL里面
13
00:00:33,513 --> 00:00:35,030
SQL语句里面
14
00:00:36,320 --> 00:00:37,840
它就有Aggregate
15
00:00:38,120 --> 00:00:38,955
的函数
16
00:00:38,955 --> 00:00:39,790
比如说
17
00:00:40,070 --> 00:00:40,393
18
00:00:40,393 --> 00:00:42,656
算总量,算平均值
19
00:00:42,656 --> 00:00:43,950
算最大值
20
00:00:43,950 --> 00:00:45,890
你看,都是什么
21
00:00:45,890 --> 00:00:48,800
很多一模一样的一个
22
00:00:49,340 --> 00:00:50,370
东西
23
00:00:50,740 --> 00:00:53,140
同一个类的不同对象
24
00:00:53,140 --> 00:00:53,673
对吧
25
00:00:53,673 --> 00:00:54,740
比如说,有
26
00:00:55,710 --> 00:00:56,135
一万个人
27
00:00:56,135 --> 00:00:58,260
你看,一万个都是人
28
00:00:58,960 --> 00:00:59,760
对吧
29
00:01:00,330 --> 00:01:04,280
然后我要算大家的平均身高多少
30
00:01:04,950 --> 00:01:05,620
31
00:01:06,380 --> 00:01:09,025
其中最高的多少
32
00:01:09,025 --> 00:01:11,935
最低是多少,最矮是多少
33
00:01:11,935 --> 00:01:14,845
你看,它是一个集合的概念
34
00:01:14,845 --> 00:01:15,110
对
35
00:01:15,390 --> 00:01:19,380
同一个类的很多很多很多对象来做一个统计
36
00:01:19,660 --> 00:01:20,730
的计算
37
00:01:21,200 --> 00:01:21,512
38
00:01:21,512 --> 00:01:22,450
所以呢
39
00:01:23,220 --> 00:01:24,910
就会导致什么
40
00:01:25,550 --> 00:01:26,720
产生了
41
00:01:27,390 --> 00:01:29,310
这样的一个错觉
42
00:01:29,590 --> 00:01:32,160
把集合当成了聚合
43
00:01:34,170 --> 00:01:37,480
所以呢,为了避免这样的错觉
44
00:01:37,760 --> 00:01:37,978
45
00:01:37,978 --> 00:01:40,820
我的推荐,就是不用这个词
46
00:01:42,350 --> 00:01:43,867
那就不用这个词
47
00:01:43,867 --> 00:01:45,132
只用哪一个
48
00:01:45,132 --> 00:01:46,903
只用这个Composition
49
00:01:46,903 --> 00:01:49,180
组合这个就行了
50
00:01:50,060 --> 00:01:53,413
一个是要用这个组合这个词表示
51
00:01:53,413 --> 00:01:54,880
它是来自不同方的
52
00:01:55,160 --> 00:01:58,250
一个组合
53
00:01:58,530 --> 00:01:59,590
类似这样
54
00:02:00,200 --> 00:02:03,490
而不是简单的一个集合这样聚集起来
55
00:02:07,180 --> 00:02:07,475
56
00:02:07,475 --> 00:02:08,360
像这个
57
00:02:16,590 --> 00:02:17,248
第二个
58
00:02:17,248 --> 00:02:18,565
我们只用这个
59
00:02:18,565 --> 00:02:20,540
我们把焦点放在什么
60
00:02:21,350 --> 00:02:22,820
放在这个
61
00:02:23,100 --> 00:02:24,275
之前也说了
62
00:02:24,275 --> 00:02:25,920
放在这个边上
63
00:02:25,920 --> 00:02:27,330
放在关系上
64
00:02:27,610 --> 00:02:28,190
65
00:02:28,650 --> 00:02:32,730
不需要用这种对应的这个
66
00:02:33,010 --> 00:02:34,350
这个词
67
00:02:36,740 --> 00:02:36,925
68
00:02:36,925 --> 00:02:38,590
这个我们就不要
69
00:02:41,220 --> 00:02:42,920
把这个改成
70
00:02:43,470 --> 00:02:45,280
用这个就行了
71
00:02:49,400 --> 00:02:50,890
那刚才的
72
00:02:52,430 --> 00:02:55,532
画面里面,我们可以看到有一个不变式
73
00:02:55,532 --> 00:02:55,920
74
00:02:56,200 --> 00:02:56,398
75
00:02:56,398 --> 00:02:57,590
有一个不变式
76
00:02:58,330 --> 00:02:58,611
77
00:02:58,611 --> 00:03:00,020
像这个早餐
78
00:03:00,740 --> 00:03:01,950
这个
79
00:03:02,340 --> 00:03:04,340
这个不变式意味着什么
80
00:03:04,650 --> 00:03:06,860
任何一个早餐对象
81
00:03:07,370 --> 00:03:08,830
它的属性值
82
00:03:09,260 --> 00:03:11,570
必须满足这样的一个约束
83
00:03:11,570 --> 00:03:11,990
对吧
84
00:03:15,710 --> 00:03:17,530
那这个不变式的话
85
00:03:17,850 --> 00:03:20,210
计算机科学里面早就有了
86
00:03:21,100 --> 00:03:24,660
那什么时候应用到面向对象领域
87
00:03:25,000 --> 00:03:27,392
最早什么时候,查的话
88
00:03:27,392 --> 00:03:27,610
89
00:03:28,050 --> 00:03:30,184
没有办法考证
90
00:03:30,184 --> 00:03:30,540
但
91
00:03:30,950 --> 00:03:34,120
至少,你看1988年的这个书
92
00:03:34,450 --> 00:03:35,030
93
00:03:36,030 --> 00:03:37,410
Meyer这个书
94
00:03:37,690 --> 00:03:39,080
这里已经有了
95
00:03:39,360 --> 00:03:42,947
已经有了专门的类的不变式的内容
96
00:03:42,947 --> 00:03:43,580
对不对
97
00:03:45,370 --> 00:03:47,242
所以呢,它不是
98
00:03:47,242 --> 00:03:49,489
领域驱动设计的发明什么之类的
99
00:03:49,489 --> 00:03:52,860
不要把那个东西塞装到那里面去
100
00:03:56,780 --> 00:04:00,120
那我们再来看一个葡萄隐喻的小问题
101
00:04:02,390 --> 00:04:05,320
为什么Evans用了一个葡萄
102
00:04:06,010 --> 00:04:06,384
103
00:04:06,384 --> 00:04:07,880
作为这个
104
00:04:08,170 --> 00:04:09,380
Aggregate
105
00:04:11,990 --> 00:04:14,270
这样的一个隐喻
106
00:04:15,950 --> 00:04:17,190
那很可能
107
00:04:17,570 --> 00:04:20,300
背后的问题是这个
0
00:00:01,230 --> 00:00:02,860
在植物学里面
1
00:00:03,880 --> 00:00:06,080
有一个聚合果的概念
2
00:00:09,350 --> 00:00:12,600
有可能,Evans是看到有这么一个词
3
00:00:13,150 --> 00:00:16,670
然后他以为这个葡萄是聚合果
4
00:00:17,020 --> 00:00:19,370
所以呢,就把葡萄给放上去了
5
00:00:21,250 --> 00:00:22,561
但实际上
6
00:00:22,561 --> 00:00:24,200
葡萄是单果
7
00:00:24,830 --> 00:00:26,380
不是聚合果
8
00:00:27,080 --> 00:00:27,487
当然
9
00:00:27,487 --> 00:00:29,730
这是属于植物学的问题
10
00:00:30,890 --> 00:00:33,180
不是软件开发的问题
0
00:00:00,220 --> 00:00:02,940
下一个我们要说的问题是
1
00:00:03,220 --> 00:00:05,720
一簇相关联的对象
2
00:00:06,110 --> 00:00:08,530
这样的说法实际上是不恰当的
3
00:00:09,200 --> 00:00:10,461
那为什么呢
4
00:00:10,461 --> 00:00:13,490
这个我们下一个视频再说了