0
00:00:01,150 --> 00:00:02,750
这个错觉
1
00:00:02,750 --> 00:00:04,030
根源之一
2
00:00:04,390 --> 00:00:06,970
可能是关系数据库
3
00:00:07,670 --> 00:00:09,861
我们拿刚才那个植物来说
4
00:00:09,861 --> 00:00:10,260
你看
5
00:00:10,660 --> 00:00:12,490
左上角是类图
6
00:00:13,230 --> 00:00:18,930
类图可能映射数据库里面,可能得到这样的数据库结构
7
00:00:19,480 --> 00:00:20,240
你看
8
00:00:21,670 --> 00:00:24,920
植物ID,ID,ID
9
00:00:25,200 --> 00:00:25,478
10
00:00:25,478 --> 00:00:26,870
你看这里面
11
00:00:27,850 --> 00:00:30,580
植物的这个数据是分散在
12
00:00:31,390 --> 00:00:33,870
各个表里面的,对不对
13
00:00:35,120 --> 00:00:38,392
所以呢,你看,这个可不就是根吗
14
00:00:38,392 --> 00:00:38,860
15
00:00:39,530 --> 00:00:40,290
16
00:00:41,800 --> 00:00:43,525
这个不就是根吗
17
00:00:43,525 --> 00:00:44,100
对吧
18
00:00:44,380 --> 00:00:44,636
19
00:00:44,636 --> 00:00:45,920
但这是什么
20
00:00:46,430 --> 00:00:48,370
这是数据库里面的
21
00:00:48,740 --> 00:00:50,410
存放的方式
22
00:00:50,810 --> 00:00:52,554
从对象的概念上
23
00:00:52,554 --> 00:00:54,050
它是一个整体
24
00:00:55,730 --> 00:00:56,300
25
00:00:57,340 --> 00:00:59,170
不是说植物对象是个根
26
00:00:59,170 --> 00:01:01,183
不是,植物对象是一个整体
27
00:01:01,183 --> 00:01:01,915
它不是根
28
00:01:01,915 --> 00:01:02,098
29
00:01:02,098 --> 00:01:03,380
刚才我们也讲了
30
00:01:04,440 --> 00:01:06,267
你把那个部件都扔掉了
31
00:01:06,267 --> 00:01:07,363
剩下就没有了
32
00:01:07,363 --> 00:01:09,921
剩下除了标识,什么都没有了
33
00:01:09,921 --> 00:01:10,470
对不对
34
00:01:11,360 --> 00:01:11,656
35
00:01:11,656 --> 00:01:17,000
所以呢,有可能是关系数据库带来的一种错觉
0
00:00:01,390 --> 00:00:05,030
第二个错觉的根源,可能是来自我们
1
00:00:05,730 --> 00:00:08,150
人类社会的观察
2
00:00:11,510 --> 00:00:13,200
在人类社会中
3
00:00:14,170 --> 00:00:15,670
比如说,我们
4
00:00:16,790 --> 00:00:18,774
我们是作为一个人
5
00:00:18,774 --> 00:00:19,436
对不对
6
00:00:19,436 --> 00:00:21,200
所以呢,我们看到的
7
00:00:21,590 --> 00:00:23,080
各种东西
8
00:00:23,450 --> 00:00:25,840
它是以人的角度来看的
9
00:00:29,990 --> 00:00:30,990
比如说
10
00:00:31,270 --> 00:00:32,980
我们经常有一个
11
00:00:34,260 --> 00:00:37,058
组织上的一个视角
12
00:00:37,058 --> 00:00:37,313
13
00:00:37,313 --> 00:00:38,840
大家可能
14
00:00:39,240 --> 00:00:40,800
看过我《软件方法》这个书
15
00:00:40,800 --> 00:00:42,360
我们说,要有组织视角
16
00:00:42,360 --> 00:00:43,400
什么组织视角
17
00:00:43,400 --> 00:00:43,920
比如说
18
00:00:45,100 --> 00:00:46,100
19
00:00:47,240 --> 00:00:48,960
某某企业
20
00:00:49,360 --> 00:00:51,220
找某某税务局
21
00:00:52,030 --> 00:00:52,920
干嘛
22
00:00:53,200 --> 00:00:53,546
23
00:00:53,546 --> 00:00:55,280
办税
24
00:00:56,330 --> 00:00:57,440
或者说
25
00:00:57,720 --> 00:01:01,250
项目部,就像这个,项目部
26
00:01:01,870 --> 00:01:02,740
找财务部
27
00:01:02,740 --> 00:01:04,045
这是两个部门
28
00:01:04,045 --> 00:01:04,480
对吧
29
00:01:05,500 --> 00:01:05,725
30
00:01:05,725 --> 00:01:07,980
每个部门各有各自责任
31
00:01:08,310 --> 00:01:09,600
项目部
32
00:01:09,880 --> 00:01:12,250
要求财务部结算
33
00:01:13,070 --> 00:01:14,870
临时工的工资
34
00:01:17,120 --> 00:01:19,329
这是两个组织之间的
35
00:01:19,329 --> 00:01:19,820
36
00:01:20,410 --> 00:01:21,660
协作
37
00:01:22,420 --> 00:01:25,910
项目部要求财务部结算工资
38
00:01:28,710 --> 00:01:29,960
但是的话
39
00:01:30,430 --> 00:01:32,580
我们作为人去观察
40
00:01:33,710 --> 00:01:36,250
实际上并没有办法观察到
41
00:01:37,190 --> 00:01:40,520
有一个巨人叫项目部
42
00:01:42,300 --> 00:01:44,445
他向财务部喊一声
43
00:01:44,445 --> 00:01:44,713
哎
44
00:01:44,713 --> 00:01:48,200
财务部,你给我结算工资,没有的
45
00:01:49,390 --> 00:01:51,120
我们会观察到什么样子
46
00:01:51,710 --> 00:01:53,703
项目部里面有个人
47
00:01:53,703 --> 00:01:54,950
有个生命体
48
00:01:55,410 --> 00:01:58,020
比如说,项目部的经理
49
00:01:58,760 --> 00:02:01,110
他向另外一个生命体
50
00:02:01,960 --> 00:02:03,400
财务部经理
51
00:02:04,260 --> 00:02:06,000
发出请求,哎
52
00:02:06,310 --> 00:02:07,360
那个
53
00:02:07,640 --> 00:02:09,215
张经理,给我们结算
54
00:02:09,215 --> 00:02:12,170
我们部门的临时工的工资
55
00:02:13,030 --> 00:02:13,681
对不对
56
00:02:13,681 --> 00:02:13,898
57
00:02:13,898 --> 00:02:15,200
这个时候,你看
58
00:02:17,120 --> 00:02:18,680
我们就会有什么
59
00:02:19,640 --> 00:02:22,050
聚合根的错觉
60
00:02:22,620 --> 00:02:25,650
这个项目部经理就是这个
61
00:02:27,600 --> 00:02:29,770
项目部的聚合根
62
00:02:30,050 --> 00:02:33,520
财务部经理就是财务部的聚合根
63
00:02:38,790 --> 00:02:41,740
因为我们的社会是人类社会
64
00:02:42,920 --> 00:02:43,990
公司
65
00:02:46,200 --> 00:02:48,040
还有政府机构等等
66
00:02:48,040 --> 00:02:49,190
是没有什么
67
00:02:49,470 --> 00:02:51,465
它是没有生命的
68
00:02:51,465 --> 00:02:53,460
它是由人组成的,对吧
69
00:02:55,410 --> 00:02:56,560
但是
70
00:02:56,840 --> 00:02:59,330
面向对象的世界里面
71
00:03:00,460 --> 00:03:02,510
对象是有生命的
72
00:03:04,270 --> 00:03:06,500
如果说,有一个部门对象
73
00:03:06,780 --> 00:03:08,394
那边也有一个部门对象
74
00:03:08,394 --> 00:03:10,170
两个互相发消息就可以了
75
00:03:10,560 --> 00:03:11,630
不需要人
76
00:03:11,910 --> 00:03:12,770
77
00:03:13,160 --> 00:03:13,860
78
00:03:14,300 --> 00:03:16,948
不需要说,有一个经理这样
79
00:03:16,948 --> 00:03:17,430
因为
80
00:03:17,860 --> 00:03:18,963
里面的对象
81
00:03:18,963 --> 00:03:21,390
我们就假设它是有生命的
82
00:03:25,560 --> 00:03:27,010
并不需要人
83
00:03:29,990 --> 00:03:31,560
实际上怎么样
84
00:03:32,030 --> 00:03:35,490
我们目前绝大多数的系统
85
00:03:35,980 --> 00:03:38,170
所描述的对象
86
00:03:39,130 --> 00:03:40,620
在现实世界中
87
00:03:41,800 --> 00:03:44,010
绝大多数是没有生命的
88
00:03:44,450 --> 00:03:46,770
比如说,订单、设备
89
00:03:47,050 --> 00:03:49,860
车辆、房间,等等
90
00:03:51,610 --> 00:03:52,580
有生命的
91
00:03:52,580 --> 00:03:55,247
像人、动物、植物
92
00:03:55,247 --> 00:03:56,460
这种是非常少的
93
00:03:57,410 --> 00:03:59,560
因为我们的软件系统
94
00:03:59,990 --> 00:04:01,750
描述的是什么
95
00:04:02,450 --> 00:04:04,800
人类的大脑
96
00:04:05,100 --> 00:04:08,440
对这个宇宙的万事万物的认识
97
00:04:09,980 --> 00:04:13,734
把人类的大脑对宇宙的万事万物认识
98
00:04:13,734 --> 00:04:16,550
把它封装到我们的软件里面
99
00:04:17,510 --> 00:04:19,108
当然,封装完了
100
00:04:19,108 --> 00:04:20,174
就可以
101
00:04:20,174 --> 00:04:21,240
用来取代
102
00:04:21,890 --> 00:04:23,570
这个人的思考了
103
00:04:23,570 --> 00:04:23,810
104
00:04:24,870 --> 00:04:26,850
那你想想,我们人
105
00:04:28,200 --> 00:04:29,317
这个领域
106
00:04:29,317 --> 00:04:31,832
人的生命体或者生命
107
00:04:31,832 --> 00:04:32,950
这个领域
108
00:04:33,450 --> 00:04:35,840
在整个宇宙万事万物里
109
00:04:36,510 --> 00:04:38,002
占多少比例
110
00:04:38,002 --> 00:04:38,748
对不对
111
00:04:38,748 --> 00:04:40,240
占不了多少的
112
00:04:40,910 --> 00:04:43,960
而且我们目前的绝大多数的系统
113
00:04:45,610 --> 00:04:48,070
还管不到这么深
114
00:04:48,070 --> 00:04:50,307
因为我们对人体的认识
115
00:04:50,307 --> 00:04:51,650
对生命的认识
116
00:04:52,570 --> 00:04:53,830
并没有那么深
117
00:04:54,110 --> 00:04:56,210
肯定没有对地球的认识
118
00:04:56,490 --> 00:04:56,687
对
119
00:04:56,687 --> 00:04:59,257
宇宙,太阳什么的认识深
120
00:04:59,257 --> 00:04:59,850
对不对
121
00:05:00,920 --> 00:05:03,170
你没有认识,你封装什么呀
122
00:05:03,170 --> 00:05:03,580
对吧
123
00:05:06,740 --> 00:05:08,800
所以这是第二点
124
00:05:10,310 --> 00:05:11,928
这是我猜测的
125
00:05:11,928 --> 00:05:14,240
为什么会有这样的错觉
126
00:05:16,310 --> 00:05:18,340
这是我们说的聚合根的
127
00:05:18,950 --> 00:05:20,354
最大的问题
128
00:05:20,354 --> 00:05:22,460
根本就不存在的
129
00:05:22,740 --> 00:05:23,510
对不对
130
00:05:26,740 --> 00:05:28,900
那其他问题
131
00:05:29,230 --> 00:05:31,243
我们下次再说了
132
00:05:31,243 --> 00:05:32,970
包括里面的
133
00:05:33,400 --> 00:05:35,596
他用葡萄做隐喻
134
00:05:35,596 --> 00:05:37,133
实际上这个是错的
135
00:05:37,133 --> 00:05:39,550
背后可能有知识误区
136
00:05:40,040 --> 00:05:43,450
还有,他用了一个词,相关联的对象
137
00:05:43,730 --> 00:05:45,767
这个用词也是有问题的
138
00:05:45,767 --> 00:05:47,620
背后也可能有知识误区
139
00:05:49,050 --> 00:05:50,090
第三点
140
00:05:52,540 --> 00:05:53,620
聚合
141
00:05:54,230 --> 00:05:57,850
或者说要建立整体-部分的关系
142
00:05:58,580 --> 00:06:01,160
我们要从逻辑的角度来思考
143
00:06:02,390 --> 00:06:04,450
而不是说从持久化
144
00:06:04,450 --> 00:06:06,053
从性能角度思考
145
00:06:06,053 --> 00:06:08,343
那就是思维颠倒了
146
00:06:08,343 --> 00:06:09,030
对不对
147
00:06:09,030 --> 00:06:11,778
我们上次说到思维颠倒
148
00:06:11,778 --> 00:06:13,610
有个视频说过了
149
00:06:14,440 --> 00:06:16,576
现在很多人就这样干
150
00:06:16,576 --> 00:06:18,950
我决定把A和B
151
00:06:19,330 --> 00:06:19,646
152
00:06:19,646 --> 00:06:20,910
当成
153
00:06:21,190 --> 00:06:21,888
聚合
154
00:06:21,888 --> 00:06:24,450
当成整体-部分的关系
155
00:06:24,730 --> 00:06:25,620
为什么呀
156
00:06:25,620 --> 00:06:28,293
因为我决定在持久化的时候
157
00:06:28,293 --> 00:06:30,520
我们以它们作为一个单元
158
00:06:32,770 --> 00:06:34,233
这不是思维颠倒吗
159
00:06:34,233 --> 00:06:34,860
对不对
160
00:06:36,050 --> 00:06:37,960
那不就是我们之前说的那个
161
00:06:40,880 --> 00:06:44,530
A跟B是泛化关系
162
00:06:45,310 --> 00:06:45,900
为什么
163
00:06:45,900 --> 00:06:47,672
因为我代码都写好了
164
00:06:47,672 --> 00:06:49,050
你看,代码都写好了
165
00:06:49,050 --> 00:06:50,821
A扩展B,A继承B嘛
166
00:06:50,821 --> 00:06:52,790
所以它不是泛化关系嘛
167
00:06:54,680 --> 00:06:55,686
那不就是什么
168
00:06:55,686 --> 00:06:56,491
你拍脑袋
169
00:06:56,491 --> 00:06:57,900
先把代码写好了
170
00:06:58,180 --> 00:07:00,201
然后再从代码来
171
00:07:00,201 --> 00:07:02,980
反证这个逻辑,不对的
172
00:07:03,260 --> 00:07:04,880
那这个我们后面
173
00:07:05,160 --> 00:07:05,370
174
00:07:05,370 --> 00:07:06,000
再说
175
00:07:06,000 --> 00:07:08,730
那感兴趣,想事先了解的同学
176
00:07:08,730 --> 00:07:10,620
可以下载这个电子书
177
00:07:11,060 --> 00:07:11,276
178
00:07:11,276 --> 00:07:12,790
里面我都有写了