搜 subtyping
https://www.zhihu.com/question/265433666/answer/337599960
https://medium.com/@mattia512maldini/inheritance-is-not-subtyping-b84488eca5ea
如果我讲 OOP,我直接从 组合优于继承 开始讲,然后讲讲 traits,讲讲这篇文章,
https://stackoverflow.com/questions/9205083/traits-vs-interfaces/9205347#9205347
“In fact, creating traits that fulfill the capabilities required by an interface is the ideal use case.”
再讲讲什么叫底层依赖高层,完事了
https://www.zhihu.com/question/265433666/answer/337599960
“一个稳定易拓展的系统应该让底层依赖高层”
然后直接讲软件设计模式里的装饰器模式
–
关于 继承 inheritance
Neither is inheritance: as a code reuse tool it is widely recognized as useless and it is slowly being discarded. Just don’t use it and no harm will come.
–
然后讲 IoC,用 IoC 来接管依赖关系并生成我需要的类的实例
这样一种叙述方式可以避免 OOP 里关于父类子类这一叙述里带来的思维弯路。它是为人脑设计的障碍
clear contracts; using interfaces will force you to think in term of communication between objects;
thinking “communication first” will give your brain free resources by splitting its job in two steps: design time and implementation time; our brain doesn’t like to work on two different things at the same time, especially switching continuously between the two;
https://codeburst.io/inheritance-is-evil-stop-using-it-6c4f1caf5117
–