当我写一个将由第三方继承的课程时,我必须应用哪些主要和最重要的规则(优点和缺点)。
谢谢。
答案 0 :(得分:11)
基本规则是: Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly 。它来自Scott Meyers的第3版优秀书籍 Effective C++ 。
Here是一些非常好的课堂设计指南。
答案 1 :(得分:7)
规则:
别。尽可能避免使用继承。
该类必须至少有一个虚函数。特别是析构函数必须是虚拟的。
该课应该是抽象的。
答案 2 :(得分:2)
... SOLID
S SRP Single responsibility principle, the notion that an object should have only a single responsibility. O OCP Open/closed principle, the notion that “software … should be open for extension, but closed for modification”. L LSP Liskov substitution principle, see also design by contract. I ISP Interface segregation principle, the notion that “many client specific interfaces are better than one general purpose interface.” D DIP Dependency inversion principle, the notion that one should “Depend upon Abstractions. Do not depend upon concretions.” Dependency injection is one method of following this principle.
取自http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29
(或者你的月份的任何首字母缩略词;)
HTH
安迪
答案 3 :(得分:1)
我来自Java背景,所以继承的规则有点不同,但这是我的观点: