0
00:00:02,960 --> 00:00:04,940
前面我们讲了
1
00:00:05,260 --> 00:00:06,810
第①句话的
2
00:00:07,090 --> 00:00:09,750
第(1)个问题和第(2)个问题
3
00:00:13,920 --> 00:00:16,930
共享父类的对象,对象树
4
00:00:16,930 --> 00:00:20,488
这样的说法是有问题的
5
00:00:20,488 --> 00:00:22,130
第二个,关联
6
00:00:22,410 --> 00:00:22,674
7
00:00:22,674 --> 00:00:23,730
这个不对
8
00:00:25,150 --> 00:00:27,737
上一期视频我们也说到了
9
00:00:27,737 --> 00:00:29,130
这里面有个反转
10
00:00:30,060 --> 00:00:32,130
那我们来看这个反转是什么
11
00:00:34,590 --> 00:00:38,000
如果没有共享父类这样的文字
12
00:00:41,690 --> 00:00:45,600
那这里的对象树,原文是图
13
00:00:46,250 --> 00:00:46,449
14
00:00:46,449 --> 00:00:48,843
它就有可能误打误撞
15
00:00:48,843 --> 00:00:50,040
就变成是对的
16
00:00:51,940 --> 00:00:53,010
为什么呢
17
00:00:56,020 --> 00:00:56,920
你看
18
00:00:57,200 --> 00:01:01,730
如果我们一个聚合组合的关联的整体的一端
19
00:01:04,410 --> 00:01:04,958
它的
20
00:01:04,958 --> 00:01:06,880
多重性上限是1
21
00:01:09,480 --> 00:01:10,703
它可以是0
22
00:01:10,703 --> 00:01:13,150
因为可能最顶上那个,像这个
23
00:01:13,660 --> 00:01:15,610
它就没有上级嘛
24
00:01:15,610 --> 00:01:16,043
25
00:01:16,043 --> 00:01:17,560
没有老大
26
00:01:19,190 --> 00:01:19,465
27
00:01:19,465 --> 00:01:24,140
那么这个整体部分的对象的链接结构
28
00:01:25,070 --> 00:01:28,290
它确实是一棵有向的树
29
00:01:28,590 --> 00:01:29,570
像这样
30
00:01:29,850 --> 00:01:31,630
你看,左边是类图
31
00:01:32,480 --> 00:01:34,520
右边是对象链接
32
00:01:34,800 --> 00:01:37,510
的形状构造
33
00:01:38,410 --> 00:01:40,948
包括上面这个ABC也行
34
00:01:40,948 --> 00:01:43,486
下面这个A的自反关联
35
00:01:43,486 --> 00:01:44,640
自反的聚合
36
00:01:44,640 --> 00:01:47,410
类图上面只有一个类A
37
00:01:47,740 --> 00:01:49,060
但是A的
38
00:01:50,470 --> 00:01:51,525
实例本身
39
00:01:51,525 --> 00:01:54,060
它也可能构成一个什么
40
00:01:54,720 --> 00:01:55,030
41
00:01:55,030 --> 00:01:56,270
构成一个
42
00:01:59,220 --> 00:02:01,330
对象的一棵树
43
00:02:02,940 --> 00:02:03,350
44
00:02:03,350 --> 00:02:04,170
就像
45
00:02:05,070 --> 00:02:06,862
商品的类别一样嘛
46
00:02:06,862 --> 00:02:07,534
对不对
47
00:02:07,534 --> 00:02:09,550
大类别下面有小类别
48
00:02:09,830 --> 00:02:10,022
49
00:02:10,022 --> 00:02:11,950
小类别下面有小小类别
50
00:02:12,260 --> 00:02:13,490
如果说
51
00:02:13,930 --> 00:02:17,040
我这里面只有一个类,叫类别
52
00:02:19,000 --> 00:02:21,590
那么类别和类别之间的这种
53
00:02:22,190 --> 00:02:25,700
关系,它就变成了递归的关联
54
00:02:26,090 --> 00:02:29,620
如果这个递归关联本身是一个
55
00:02:30,860 --> 00:02:32,630
一对多的,就是说
56
00:02:33,060 --> 00:02:35,930
一个下级只能有一个上级
57
00:02:36,360 --> 00:02:39,035
一个上级可以有多个下级
58
00:02:39,035 --> 00:02:41,710
它确实就是一棵这样的树
59
00:02:46,310 --> 00:02:48,840
那如果不是一对多
60
00:02:49,400 --> 00:02:51,000
整体这一端
61
00:02:51,930 --> 00:02:53,570
它可以是多的
62
00:02:54,690 --> 00:02:55,480
63
00:02:56,800 --> 00:02:58,880
就是一个部分对象
64
00:02:59,510 --> 00:03:02,150
可以属于多个整体对象
65
00:03:02,510 --> 00:03:06,680
当然这个时候,所谓的整体部分
66
00:03:07,710 --> 00:03:09,220
就已经没有
67
00:03:09,950 --> 00:03:11,051
严谨的含义了
68
00:03:11,051 --> 00:03:12,519
含义已经模糊了
69
00:03:12,519 --> 00:03:13,070
对不对
70
00:03:13,350 --> 00:03:14,772
你既然是部分
71
00:03:14,772 --> 00:03:18,327
你还能够同时属于别人,不行的
72
00:03:18,327 --> 00:03:19,750
你应该是什么
73
00:03:20,170 --> 00:03:22,440
在同一个时间内,啪
74
00:03:22,740 --> 00:03:24,230
拍一张快照
75
00:03:24,620 --> 00:03:27,710
应该是什么样,只能够拍到
76
00:03:28,030 --> 00:03:29,400
它只属于
77
00:03:30,600 --> 00:03:31,770
一个整体
78
00:03:32,360 --> 00:03:35,040
当然你可以把它转移
79
00:03:35,530 --> 00:03:37,833
比如说,你本来是他的小弟
80
00:03:37,833 --> 00:03:38,880
是属于他的
81
00:03:39,700 --> 00:03:42,160
现在你被他抛弃了
82
00:03:42,440 --> 00:03:43,777
他把你解除了
83
00:03:43,777 --> 00:03:45,114
扔到一边去了
84
00:03:45,114 --> 00:03:48,457
另外一个老大把你捡起来,这可以
85
00:03:48,457 --> 00:03:48,902
对吧
86
00:03:48,902 --> 00:03:52,245
但是同一时间,你不可能拍到,啪
87
00:03:52,245 --> 00:03:53,360
同一个
88
00:03:53,640 --> 00:03:57,230
部分属于两个或多个
89
00:03:57,570 --> 00:03:59,830
不同的整体,那就不对了
90
00:04:01,180 --> 00:04:04,972
如果说一个部分对象
91
00:04:04,972 --> 00:04:07,890
可以同时属于多个的话
92
00:04:08,250 --> 00:04:10,110
那就可以是这样了
93
00:04:10,110 --> 00:04:12,383
就变成一张有向无环图
94
00:04:12,383 --> 00:04:13,830
变成一张图了
95
00:04:13,830 --> 00:04:14,450
对不对
96
00:04:15,470 --> 00:04:15,648
97
00:04:15,648 --> 00:04:18,501
但这个时候这个含义已经模糊了
98
00:04:18,501 --> 00:04:20,285
所以呢,这个我们只是说
99
00:04:20,285 --> 00:04:21,533
如果是这样的情况
100
00:04:21,533 --> 00:04:24,030
但不代表这样的情况是提倡的
101
00:04:24,310 --> 00:04:26,539
那就无所谓什么整体部分关系
102
00:04:26,539 --> 00:04:28,597
变成普通关联就行了
103
00:04:28,597 --> 00:04:28,940
对吧
104
00:04:32,090 --> 00:04:33,950
那为什么是有向
105
00:04:34,890 --> 00:04:36,800
因为这个
106
00:04:37,080 --> 00:04:38,840
组合聚合关系
107
00:04:39,770 --> 00:04:41,920
它是非对称的
108
00:04:42,440 --> 00:04:44,423
实际上,我们的继承关系
109
00:04:44,423 --> 00:04:46,226
或者泛化关系也是非对称的
110
00:04:46,226 --> 00:04:48,210
只不过这个非对称是什么
111
00:04:48,490 --> 00:04:51,690
它是在集合的层面上非对称
112
00:04:52,300 --> 00:04:53,610
不能说
113
00:04:54,070 --> 00:04:55,635
A是B的一种
114
00:04:55,635 --> 00:04:57,200
B是C的一种
115
00:04:57,480 --> 00:04:59,468
然后C又是A的一种
116
00:04:59,468 --> 00:05:00,793
那不行的
117
00:05:00,793 --> 00:05:02,561
不可能是这样
118
00:05:02,561 --> 00:05:03,003
对吧
119
00:05:03,003 --> 00:05:05,433
泛化,集合的包含嘛
120
00:05:05,433 --> 00:05:06,980
而聚合组合关系
121
00:05:08,620 --> 00:05:10,222
也是非对称的
122
00:05:10,222 --> 00:05:14,230
如果B对象是A对象的一部分的话
123
00:05:15,230 --> 00:05:16,310
那么A
124
00:05:16,590 --> 00:05:20,250
就不可能直接或间接成为B的部分
125
00:05:20,890 --> 00:05:21,121
126
00:05:21,121 --> 00:05:25,280
所以呢,在对象级别上不可能有这样的
127
00:05:26,050 --> 00:05:26,870
128
00:05:27,920 --> 00:05:29,660
A组合B
129
00:05:29,950 --> 00:05:30,176
130
00:05:30,176 --> 00:05:31,990
B是A的一部分
131
00:05:32,270 --> 00:05:35,356
然后C又是B的一部分
132
00:05:35,356 --> 00:05:37,320
然后C反过来又
133
00:05:37,720 --> 00:05:39,560
组合A,那不行的
134
00:05:40,840 --> 00:05:43,810
就像汽车有轮子
135
00:05:43,810 --> 00:05:44,405
136
00:05:44,405 --> 00:05:47,970
轮子上面呢,有个轴承
137
00:05:48,450 --> 00:05:50,960
有个轮子的芯
138
00:05:51,830 --> 00:05:52,025
139
00:05:52,025 --> 00:05:53,000
ABC嘛
140
00:05:53,000 --> 00:05:55,925
然后这个芯反过来组装了这个汽车
141
00:05:55,925 --> 00:05:56,900
怎么可能呢
142
00:05:56,900 --> 00:05:57,290
对吧
143
00:06:00,560 --> 00:06:04,285
要注意,我们这里说的是对象级别
144
00:06:04,285 --> 00:06:07,080
有的同学这里搞不清楚,说
145
00:06:07,360 --> 00:06:08,530
可以呀
146
00:06:09,550 --> 00:06:12,120
我这个轮子里面
147
00:06:12,430 --> 00:06:14,780
可以再组装一个汽车对象
148
00:06:16,900 --> 00:06:18,178
汽车组装轮子
149
00:06:18,178 --> 00:06:19,243
轮子也组装汽车
150
00:06:19,243 --> 00:06:19,670
151
00:06:20,110 --> 00:06:22,205
可不可以,可以的
152
00:06:22,205 --> 00:06:24,900
但是,那个汽车对象跟
153
00:06:25,180 --> 00:06:28,987
这个汽车对象不是同一个汽车对象
154
00:06:28,987 --> 00:06:30,510
搞清楚
155
00:06:31,250 --> 00:06:32,427
就像我们这个
156
00:06:32,427 --> 00:06:32,820
你看
157
00:06:33,580 --> 00:06:36,916
A自己组装A,可不可以,可以呀
158
00:06:36,916 --> 00:06:37,430
对吧
159
00:06:37,750 --> 00:06:37,959
160
00:06:37,959 --> 00:06:39,633
部门里面有小部门
161
00:06:39,633 --> 00:06:40,888
两个都是部门
162
00:06:40,888 --> 00:06:43,190
但是大部门里面有小部门
163
00:06:43,610 --> 00:06:46,661
但这里经常很多人在这里糊涂的
164
00:06:46,661 --> 00:06:48,950
特别是很多现在的程序员
165
00:06:49,490 --> 00:06:51,500
缺少基本的训练
166
00:06:53,350 --> 00:06:55,063
基本的抽象能力都没有
167
00:06:55,063 --> 00:06:57,290
经常这个就把他打晕掉了
168
00:07:01,280 --> 00:07:03,021
这是类级别上的
169
00:07:03,021 --> 00:07:05,198
但是展开到对象级别上
170
00:07:05,198 --> 00:07:07,157
它是不同的对象
171
00:07:07,157 --> 00:07:07,810
对不对
172
00:07:08,510 --> 00:07:09,340
173
00:07:10,150 --> 00:07:12,990
很多同学这里经常就出问题的
0
00:00:00,770 --> 00:00:02,336
类似这样的观点
1
00:00:02,336 --> 00:00:04,250
我前面已经说过很多遍了
2
00:00:04,680 --> 00:00:05,360
3
00:00:05,640 --> 00:00:08,287
比如说,一个人
4
00:00:08,287 --> 00:00:11,230
他说我觉得
5
00:00:12,000 --> 00:00:13,416
很多搞迷信的
6
00:00:13,416 --> 00:00:14,597
这些是对的
7
00:00:14,597 --> 00:00:14,833
8
00:00:14,833 --> 00:00:16,250
我就信那个
9
00:00:17,030 --> 00:00:17,228
10
00:00:17,228 --> 00:00:18,615
这是他的自由
11
00:00:18,615 --> 00:00:20,200
但如果说这个人
12
00:00:21,360 --> 00:00:21,932
他说
13
00:00:21,932 --> 00:00:24,224
我的迷信这一套就比科学强
14
00:00:24,224 --> 00:00:25,560
我要证明给你看
15
00:00:25,560 --> 00:00:27,470
你科学没什么了不起的
16
00:00:28,080 --> 00:00:28,300
17
00:00:28,300 --> 00:00:30,285
他就认真去学科学
18
00:00:30,285 --> 00:00:31,167
学物理
19
00:00:31,167 --> 00:00:32,270
学化学,等等
20
00:00:32,560 --> 00:00:35,460
还去参加高考,结果呢
21
00:00:35,740 --> 00:00:36,922
高考
22
00:00:36,922 --> 00:00:38,500
物理、化学考了很高的分
23
00:00:41,720 --> 00:00:42,720
你想想
24
00:00:43,000 --> 00:00:44,930
如果一个人他能够
25
00:00:45,350 --> 00:00:47,470
考到这么高的分的话
26
00:00:47,890 --> 00:00:51,020
他有可能回去信之前的那一套吗
27
00:00:51,310 --> 00:00:52,716
他不可能的
28
00:00:52,716 --> 00:00:53,560
对不对
29
00:00:55,540 --> 00:00:58,377
我们之所以很多时候信那些东西
30
00:00:58,377 --> 00:01:01,620
就是因为什么,我们没有认真去学习过
31
00:01:01,900 --> 00:01:04,450
比较严谨的一些思维
32
00:01:09,190 --> 00:01:10,540
这是第(3)点
33
00:01:11,960 --> 00:01:13,680
第(4)点就是
34
00:01:14,380 --> 00:01:14,650
35
00:01:14,650 --> 00:01:17,900
确实为什么有这样的误解
36
00:01:18,200 --> 00:01:21,063
跟译者本身的知识的缺陷有关
37
00:01:21,063 --> 00:01:25,470
但是呢,原文的parent这个词确实用得不好
38
00:01:26,950 --> 00:01:29,820
因为这个往往是用在类上面
39
00:01:30,100 --> 00:01:30,363
40
00:01:30,363 --> 00:01:31,680
应该是整体
41
00:01:31,960 --> 00:01:32,209
42
00:01:32,209 --> 00:01:35,700
整体对象,这样用更好一点
43
00:01:40,700 --> 00:01:42,270
那建议的译文
44
00:01:42,550 --> 00:01:42,770
45
00:01:42,770 --> 00:01:43,870
就这样
46
00:01:43,870 --> 00:01:46,730
聚合只是把共同父对象之下的
47
00:01:46,730 --> 00:01:48,050
%……&&¥¥
48
00:01:48,570 --> 00:01:50,670
我们就忠实地
49
00:01:50,950 --> 00:01:52,283
根据原文来译
50
00:01:52,283 --> 00:01:55,330
这里父对象,这个我们依然留下来
51
00:01:55,770 --> 00:01:56,010
52
00:01:56,010 --> 00:01:57,450
不改成整体
53
00:02:01,060 --> 00:02:01,292
好
54
00:02:01,292 --> 00:02:02,684
这是第①句了
55
00:02:02,684 --> 00:02:04,540
那我们来看第②句
56
00:02:09,720 --> 00:02:10,870
第②句
57
00:02:10,870 --> 00:02:13,170
这是原文和译文
58
00:02:13,850 --> 00:02:16,530
那问题呢,有这么几个
59
00:02:17,660 --> 00:02:18,790
比较大的
60
00:02:19,070 --> 00:02:19,890
这个
61
00:02:20,270 --> 00:02:22,520
(1)(2)这是比较大的了
62
00:02:24,630 --> 00:02:25,740
你看这里
63
00:02:26,180 --> 00:02:27,590
它说“遍历”
64
00:02:28,640 --> 00:02:30,240
但这里并没有说遍历
65
00:02:30,240 --> 00:02:31,130
只是说什么
66
00:02:32,290 --> 00:02:33,920
导航
67
00:02:34,280 --> 00:02:34,568
68
00:02:34,568 --> 00:02:36,300
没有说遍历
69
00:02:36,890 --> 00:02:38,180
只是说导航
70
00:02:38,780 --> 00:02:39,730
第(2)个
71
00:02:40,010 --> 00:02:42,450
这里有个深度的递归
72
00:02:44,110 --> 00:02:45,020
这里面
73
00:02:45,300 --> 00:02:46,998
有一个深地
74
00:02:46,998 --> 00:02:49,830
这个有,没有说递归
75
00:02:51,440 --> 00:02:54,453
那为什么会有这样的一个译文出来
76
00:02:54,453 --> 00:02:57,668
背后有什么样的思想上的根源
77
00:02:57,668 --> 00:03:00,280
可能有什么样的思想上的根源
78
00:03:00,840 --> 00:03:01,248
79
00:03:01,248 --> 00:03:02,880
这个我们
80
00:03:03,160 --> 00:03:04,130
下期
81
00:03:04,610 --> 00:03:04,843
82
00:03:04,843 --> 00:03:06,480
我们再来探讨