3月 4
Containment
* 通过包含来实现“有一个/has a”的关系
* 在万不得已时通过private继承来实现“有一个”的关系
* 警惕有超过约7个数据成员的类
Inheritance
* 用public继承来实现“是一个/is a”的关系
* 要么使用继承并进行详细说明,要么就不要用它
* 遵循Liskov替换原则LSP
* 确保只继承需要继承的部分
* 不要覆盖一个不可覆盖的成员函数
* 把公用的接口、数据及操作放到继承树中尽可能高的位置
* 只有一个实例的类是值得怀疑的(特例:单件模式)
* 只有一个派生类的基类也值得怀疑 (提前设计)
* 派生后覆盖了某个子程序,但在其中没有任何操作,这种情况也值得怀疑
* 避免让继承体系过深
* 尽量使用多态,避免大量的类型检查
* 让所有的数据都是private(而非protected)

知识来源: 《代码大全2》 P143-P148
Defined tags for this entry:

作者 rollenc

| 主要出源 (0)
请对 365 天内更新的文章进行打分
当前分数: 1.83 of 5 。 6 次打分。 268 次点击
Bookmark 包含和继承  at del.icio.us Digg 包含和继承 Mixx 包含和继承 Bloglines 包含和继承 Technorati 包含和继承 Fark this: 包含和继承 Bookmark 包含和继承  at YahooMyWeb Bookmark 包含和继承  at Furl.net Bookmark 包含和继承  at reddit.com Bookmark 包含和继承  at blinklist.com Bookmark 包含和继承  at Spurl.net Bookmark 包含和继承  at NewsVine Bookmark 包含和继承  at Simpy.com Bookmark 包含和继承  at blogmarks Bookmark 包含和继承  with wists Bookmark 包含和继承  at Ma.gnolia.com wong it! Bookmark using any bookmark manager! Stumble It!

0 引用

  1. 没有引用

0 回复

回复显示方式(直线程 | 分线程)
  1. 没有回复

新增回复


You can use [geshi lang=lang_name [,ln={y|n}]][/lang] tags to embed source code snippets
电子邮件地址将不会被显示,而仅将被用于发送电子邮件通知

为了阻止机器人提交垃圾回复,请在相应的文本框中输入你在下面的图片中所看到的字符串。只有在你输入的字符串和图片中的字符串吻合的情况下,你的回复才能被成功提交。请确认你的浏览器支持、并且已经开启了cookies功能,否则的话,你的回复无法被正确地验证。
CAPTCHA