0
00:00:06,080 --> 00:00:08,470
上两个视频我们
1
00:00:09,200 --> 00:00:11,860
说了两个问题
2
00:00:11,860 --> 00:00:14,520
就是说,首先
3
00:00:15,370 --> 00:00:17,230
强调某某
4
00:00:17,520 --> 00:00:17,828
5
00:00:17,828 --> 00:00:19,988
是Aggregate,聚合体
6
00:00:19,988 --> 00:00:21,840
这个没有必要
7
00:00:22,860 --> 00:00:23,922
哪个不是呢
8
00:00:23,922 --> 00:00:24,560
对不对
9
00:00:25,200 --> 00:00:25,518
10
00:00:25,518 --> 00:00:28,070
第二个,这个聚合根
11
00:00:28,670 --> 00:00:31,200
这是一个错误的伪创新
12
00:00:32,840 --> 00:00:36,010
实际上,我们只需要说一句话就可以了
13
00:00:37,900 --> 00:00:39,360
对象的部件
14
00:00:39,840 --> 00:00:41,740
只能由对象来访问
15
00:00:42,750 --> 00:00:44,040
这就够了
16
00:00:45,080 --> 00:00:48,290
不用搞出很多很多玄乎玄乎的东西来
17
00:00:48,570 --> 00:00:48,742
18
00:00:48,742 --> 00:00:52,010
所有的责任你都按照这个原则来做就可以
19
00:00:54,180 --> 00:00:56,011
但是有些人他就喜欢搞
20
00:00:56,011 --> 00:00:57,660
把这东西搞得很玄乎
21
00:00:58,060 --> 00:00:58,292
22
00:00:58,292 --> 00:00:59,690
就像那个什么
23
00:00:59,690 --> 00:01:03,651
我们知道有很多很多什么被捏造出来的
24
00:01:03,651 --> 00:01:05,049
什么什么原则
25
00:01:05,049 --> 00:01:06,680
什么o c p是吧
26
00:01:07,130 --> 00:01:08,310
应该
27
00:01:08,590 --> 00:01:09,057
呃
28
00:01:09,057 --> 00:01:10,460
d i p
29
00:01:10,760 --> 00:01:11,008
嗯
30
00:01:11,008 --> 00:01:13,000
s r p什么什么p
31
00:01:14,630 --> 00:01:15,243
然后呢
32
00:01:15,243 --> 00:01:20,150
他就把它渲染成什么面向对象设计的几大原则什么的
33
00:01:20,150 --> 00:01:24,240
实际上都是那个网红圈子里面的人圈传出来的
34
00:01:24,780 --> 00:01:27,820
实际上里面就是一个泛化关系
35
00:01:28,100 --> 00:01:28,910
对吧
36
00:01:30,330 --> 00:01:31,300
就完了
37
00:01:31,660 --> 00:01:31,896
嗯
38
00:01:31,896 --> 00:01:34,970
什么事情他就拿一个来做一个
39
00:01:35,250 --> 00:01:36,238
泛化关系
40
00:01:36,238 --> 00:01:37,720
然后呢就搞定
41
00:01:38,610 --> 00:01:41,696
然后就把它搞搞出很多很多乱七八糟的来
42
00:01:41,696 --> 00:01:42,553
搞得很玄乎
43
00:01:42,553 --> 00:01:44,440
反正就那么一点点东西
44
00:01:48,740 --> 00:01:50,930
那今天呢,我们
45
00:01:51,850 --> 00:01:52,890
再来看
46
00:01:53,210 --> 00:01:54,490
第三个问题
47
00:01:56,070 --> 00:01:57,370
葡萄隐喻
48
00:02:04,340 --> 00:02:06,440
在Evans的书里面
49
00:02:07,040 --> 00:02:09,210
他用了一串葡萄
50
00:02:09,560 --> 00:02:09,923
51
00:02:09,923 --> 00:02:12,470
来隐喻聚合
52
00:02:15,040 --> 00:02:18,510
但是这个隐喻是不恰当的
0
00:00:00,890 --> 00:00:02,290
一串葡萄
1
00:00:02,920 --> 00:00:04,950
就算有一亿颗葡萄
2
00:00:05,690 --> 00:00:07,550
它也是一个集合
3
00:00:07,950 --> 00:00:12,100
除非这个串本身有特定的含义
4
00:00:15,530 --> 00:00:17,610
概念本身,它
5
00:00:17,890 --> 00:00:19,630
肯定是一个单数的
6
00:00:20,060 --> 00:00:20,299
7
00:00:20,299 --> 00:00:21,255
否则的话
8
00:00:21,255 --> 00:00:25,080
如果你可以对这个集合再来
9
00:00:25,430 --> 00:00:26,857
定一个概念的话
10
00:00:26,857 --> 00:00:29,100
那所有的概念都会翻两倍
11
00:00:29,100 --> 00:00:29,712
对不对
12
00:00:29,712 --> 00:00:30,120
比如,人
13
00:00:30,580 --> 00:00:31,260
14
00:00:33,120 --> 00:00:37,155
人,这个概念,我们可以理解
15
00:00:37,155 --> 00:00:37,660
人们
16
00:00:38,530 --> 00:00:40,013
那不就是人的集合嘛
17
00:00:40,013 --> 00:00:41,681
人们要不要搞一个类
18
00:00:41,681 --> 00:00:42,793
叫人们
19
00:00:42,793 --> 00:00:43,350
不需要
20
00:00:44,040 --> 00:00:45,770
除非这个人们
21
00:00:46,050 --> 00:00:47,640
有特定含义
22
00:00:48,760 --> 00:00:48,993
23
00:00:48,993 --> 00:00:51,795
比如说,顾客,张三是一名顾客
24
00:00:51,795 --> 00:00:52,730
这个我们
25
00:00:53,380 --> 00:00:54,520
这个可以理解
26
00:00:54,520 --> 00:00:54,900
对吧
27
00:00:54,900 --> 00:00:56,420
顾客们,就没有必要
28
00:00:57,000 --> 00:00:58,170
除非什么
29
00:00:58,480 --> 00:01:01,260
它又变成了一个单数的概念
30
00:01:01,540 --> 00:01:04,462
比如说,顾客组成一个团,团购
31
00:01:04,462 --> 00:01:05,680
里面那个团
32
00:01:06,190 --> 00:01:06,492
33
00:01:06,492 --> 00:01:08,310
这时候,这个团
34
00:01:08,590 --> 00:01:10,372
里面有很多名顾客
35
00:01:10,372 --> 00:01:10,595
36
00:01:10,595 --> 00:01:14,160
这个团就可以是另外一个概念
37
00:01:14,440 --> 00:01:17,870
这可以,那这个团这时候也是一个单数的
38
00:01:19,890 --> 00:01:23,397
不能说顾客们成为一个类
39
00:01:23,397 --> 00:01:24,136
没有必要
40
00:01:24,136 --> 00:01:24,690
对不对
41
00:01:26,140 --> 00:01:28,210
那什么样的一个
42
00:01:29,240 --> 00:01:32,090
整体-部分关系是有意义的
43
00:01:33,390 --> 00:01:34,860
就下面这个了
44
00:01:36,240 --> 00:01:37,560
一份早餐
45
00:01:38,720 --> 00:01:44,560
由若干颗葡萄,加若干个煎蛋,加若干根油条
46
00:01:45,050 --> 00:01:46,640
组合而成
47
00:01:48,230 --> 00:01:49,662
而这几个组合里面
48
00:01:49,662 --> 00:01:51,452
它就有这样的一个约束
49
00:01:51,452 --> 00:01:51,810
你看
50
00:01:52,750 --> 00:01:55,770
葡萄里面的维生素的含量
51
00:01:56,850 --> 00:01:57,990
要大于
52
00:01:58,750 --> 00:02:01,030
煎蛋里面的蛋白质含量
53
00:02:01,780 --> 00:02:04,030
否则这个早餐就是
54
00:02:04,820 --> 00:02:07,220
营养不均衡
55
00:02:10,820 --> 00:02:11,020
56
00:02:11,020 --> 00:02:12,820
这个才是有意义的
57
00:02:14,070 --> 00:02:16,332
你光葡萄,很多很多
58
00:02:16,332 --> 00:02:16,897
葡萄
59
00:02:16,897 --> 00:02:19,160
这个意义并不大
60
00:02:24,220 --> 00:02:26,530
平时我们见到的这种
61
00:02:26,810 --> 00:02:28,190
很多很多这种
62
00:02:28,190 --> 00:02:30,030
比如说,订单-订单项
63
00:02:31,650 --> 00:02:33,975
看起来好像跟这个葡萄
64
00:02:33,975 --> 00:02:34,750
很多葡萄,这个
65
00:02:35,270 --> 00:02:36,446
是相似的
66
00:02:36,446 --> 00:02:38,210
实际上不是的
67
00:02:38,810 --> 00:02:41,720
订单-订单项这个
68
00:02:43,810 --> 00:02:45,690
只是一个简化版
69
00:02:46,500 --> 00:02:48,710
如果仅仅是这样的话
70
00:02:49,120 --> 00:02:51,728
这个订单就没有必要存在了
71
00:02:51,728 --> 00:02:52,380
对不对
72
00:02:53,750 --> 00:02:55,600
它就是一个简单的集合
73
00:02:57,930 --> 00:03:00,320
订单之所以存在
74
00:03:01,220 --> 00:03:04,072
原因就是它不只是有这个
75
00:03:04,072 --> 00:03:05,629
它还得有顾客
76
00:03:05,629 --> 00:03:06,407
有地址
77
00:03:06,407 --> 00:03:07,703
有下单日期
78
00:03:07,703 --> 00:03:09,260
什么什么什么
79
00:03:10,980 --> 00:03:13,160
而且它背后可能会有一个约束
80
00:03:13,730 --> 00:03:14,660
对不对
81
00:03:15,830 --> 00:03:18,210
所以才会有订单这个类
82
00:03:19,790 --> 00:03:24,416
之所以你看到这个,那只是一个简略版
83
00:03:24,416 --> 00:03:26,840
它肯定还有别的属性的
84
00:03:27,130 --> 00:03:29,030
比如说,像下面这些
85
00:03:29,030 --> 00:03:32,355
这个是,这个是,这个是,有的简单
86
00:03:32,355 --> 00:03:33,305
有的复杂
87
00:03:33,305 --> 00:03:34,017
有的多
88
00:03:34,017 --> 00:03:35,442
有的是多个的
89
00:03:35,442 --> 00:03:36,630
有的是一个的