最大可接受图层/继承级别 [英] Maximum Accepted Layers/Levels of inheritance

查看:65
本文介绍了最大可接受图层/继承级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






正常C ++程序中具有私有(数据),受保护的最大接受层数/继承级别(数据)和

公共(数据,会员功能)?

这取决于什么?


优先购买者,

Karthik Balaguru

Hi,

What could be the maximum Accepted Layers/Levels of inheritance in a
normal C++ program that has private(data),protected(data) and
public(data,member functions) ?
On what does this depend upon ?

Thx in advans,
Karthik Balaguru

推荐答案

[CC''d到设计新闻组,因为答案不是特定于C ++]


karthikbalaguru写道:
[CC''d to a design newsgroup, because the answer is not specific to C++]

karthikbalaguru wrote:

什么是
普通的C ++程序,它有私有(数据),受保护(数据)和

公共(数据,成员函数)?
What could be the maximum Accepted Layers/Levels of inheritance in a
normal C++ program that has private(data),protected(data) and
public(data,member functions) ?



不要......


- 设计所有课程预先之前

编码其中任何一个

- 使用继承作为可编辑的评论

- 使用公共数据

- 滥用受保护的数据 - 使用虚拟访问器

Don''t...

- design all your classes "up front" before
coding any of them
- use inheritance as a "compilable comment"
- use public data
- abuse protected data - use virtual accessors instead


这取决于什么?
On what does this depend upon ?



好​​的软件...


- 通过所有自动化测试

- 很清楚可读的

- 重复没有行为代码

- 最小化行,方法和类


从本书/设计模式/开始,通常要了解所有这些OO内容的点

是什么。您会注意到大多数模式只使用2层

继承 - 一个抽象的界面类,以及

继承自它的具体类。太多的继承是设计气味,因为

继承是耦合的最强形式之一,我们应该

而不是想要经过精心管理的类事物之间的依赖关系。


-

Phlip
http://www.oreilly.com/catalog/9780596510657/

^ assert_xpath

Good software...

- passes all automated tests
- is clear and readable
- duplicates no behavioral code
- minimizes lines, methods, and classes

Start with the book /Design Patterns/, generally to learn what the "point"
of all this OO stuff is. You will notice most patterns use only 2 layers of
inheritance - an abstract interfacial class, and concrete classes that
inherit from it. Too much inheritance is a "design smell", because
inheritance is one of the strongest forms of "coupling", and we should
instead want classes with carefully managed dependencies between things.

--
Phlip
http://www.oreilly.com/catalog/9780596510657/
^ assert_xpath


karthikbalaguru写道:
karthikbalaguru wrote:




什么是最大可接受的图层/继承级别一个正常的C ++程序,它有私有(数据),受保护(数据)和公共(数据,成员函数)吗?
Hi,

What could be the maximum Accepted Layers/Levels of inheritance in a
normal C++ program that has private(data),protected(data) and
public(data,member functions) ?



a)如果你在谈论编码指南,那么任何数字都可能是你的b / b
上级可接受的个人上限: - )


b)如果你在谈论编译器是否会接受你的代码,

标准[附件B]建议实现支持带有
$的类b $ b最多16384个直接和间接基类。是否你想要那个

远,取决于你。

a) If you are talking about coding guidelines, then any number could be your
superiors personal upper bound of acceptability:-)

b) If you are talking about whether the compiler will accept your code, the
standard [Annex B] recommends that an implementation supports classes with
up to 16384 direct and indirect base classes. Whether you want to go that
far, is up to you.


这取决于什么?
On what does this depend upon ?



对于(a),经验,品味和当地文化。


对于(b),实施。< br $> b $ b最好


Kai-Uwe Bux

For (a), experience, taste, and local culture.

For (b), the implementation.
Best

Kai-Uwe Bux


Phlip写道:
Phlip wrote:

好​​的软件......

- 最小化行,方法和类
Good software...
- minimizes lines, methods, and classes



但是避免混淆。


还要注意 http:// en.wikipedia.org/wiki/Abstraction_inversion


此外,不应通过创建
http://en.wikipedia.org/wiki/God_object

这篇关于最大可接受图层/继承级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆