作者xxxorc ()
看板Soft_Job
标题Re: [请益] 我这样解释OOP对吗?
时间Thu Nov 16 15:30:33 2017
想请问各位工程师在使用别人写好的套件时
会直接使用继承来复用套件中的 class ,还是会封装一层当作黑箱来用呢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.251.70.124
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Soft_Job/M.1510817436.A.74F.html
1F:→ loveflames: 继承? 不先选择组合吗 11/16 15:38
2F:→ xxxorc: 用组合的话 如果命名很类似怎麽办 11/16 15:39
3F:推 legendmtg: 别人写的东西不见得有为了要被继承而设计 11/16 15:42
4F:→ legendmtg: 随便继承下去不小心就炸了 11/16 15:42
5F:→ legendmtg: 命名类似有namespace啊 11/16 15:43
6F:推 ripple0129: Composition over inheritance 11/16 18:52
7F:推 sunsamy: It's right: Composition over inheritance. 11/16 20:54
8F:→ sunsamy: Because doesn't have overriding or overloading to 11/16 20:55
9F:→ sunsamy: confuse relation. 11/16 20:56
10F:推 loveflames: 如果非要继承,继承抽象比继承实作好 11/16 20:56
11F:推 sunsamy: 继承抽象比继承实作好: 因为解耦掉底层的实作 11/16 21:04
12F:→ sunsamy: 在runtime时才对应实作(i.e. Polymorphism、泛形、Templa 11/16 21:04
13F:→ sunsamy: te) 11/16 21:05
14F:→ sunsamy: 如:linux的HAL层解耦掉底层的IC的PolicyBased Design Pat 11/16 21:05
15F:→ sunsamy: tern 11/16 21:05
16F:→ loveflames: 进一步抽象可使用bridge,将介面与实作解耦 11/16 21:30
17F:→ Killercat: 通常来讲组合比继承好,不过要看对方介面怎麽设计 11/22 15:13
18F:→ Killercat: 至於介面实作是更好 但是很吃设计 包含自己跟对方 11/22 15:14
19F:推 bitcch: 我会用封装 继承的耦合太大了 11/28 15:15