deep and shallow inheritance tree in C++
怪我咯
怪我咯 2017-04-17 11:56:59
0
1
517

读Goodrich的 Data Structures and Algorithms in C++, 2nd Edition.

第二章的习题:
"R-2.1 What are some potential efficiency disadvantages of having very deep in- heritance trees, that is, a large set of classes, A, B, C, and so on, such that B extends A, C extends B, D extends C, etc.?"

"R-2.2 What are some potential efficiency disadvantages of having very shallow inheritance trees, that is, a large set of classes, A, B, C, and so on, such that all of these classes extend a single class, Z?"


deep inheritance, 就是 A -> B -> C -> D.

shallow inheritance, 就是 A -> B, A -> C, A -> D.

这是个十分宽泛的, 带有启发性的问题, efficiency 既可以指runtime efficiency 也可以指 高效的开发原则.

对于runtime efficiency, 根据stack overflow上的回答, 大部分C++的操作对于inheritance hierarchy的size都是invariant的 (除了dynamic_castlinearly depends on the size), 所以deep inheritance实际上的开销并不多?

对于开发来讲, A -> B, A -> C, A -> D 的一个应用场景既是的C++ 中的 interface (类似java?), 在其他的场合其实并不多?

我初识C++, 以上黑体的部分是我的疑惑.

怪我咯
怪我咯

走同样的路,发现不同的人生

全員に返信(1)
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!