由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教一个class design的问题
相关主题
C++ virtual function 定义在 derived class 会怎么样?c++ question, thanks
请问C++小白问题[合集] protected inheritance in C++
C++ private inheritance. v.s. compositionHow to understand the answer.
问一个inheritance的初级问题什么地方用到 Private inheritance
friend function 不能virtual 怎么搞呢?C++ Primer 上关于inheritance protected member 的一段话
请问c++中操作符可以声明为虚函数吗?virtual function question
弱问一个virtual function的问题【讨论】问一道很简单的C++题。。。。 (转载)
一个inheritance 的问题问一下这个cast在java里是怎么work的
相关话题的讨论汇总
话题: class话题: new话题: function话题: hierachy话题: 一样
进入Programming版参与讨论
1 (共1页)
l**********o
发帖数: 22
1
我现在有一个比较大的class structure大致是这样的
A (abc)
|
B
/ \
C D
/ \ |
E F G
/ \ |
H I J
现在要做一个新的class,从project的概念上讲是和class B大概是类似eclipse和
circle的关系,但是就具体内容而言,也就是里面的一小部分function不一样,但是
new class其他大部分function和B 一样,它的derive结构也一样,只是它的相对应的
derived class也和B 的每一个derived class几乎一样只有少部分function不同。 在
这种情况下,我该怎么设计这个new class呢?我也不想把大段的code直接copy,但又
想不出怎么安排这个new class和现有class,有经验的请指点一下,谢谢!
g*****g
发帖数: 34805
2
Pull out the similar functions from the class hierachy, call it
A', B', C' etc. Let B and your new class extends B'.
Also consider composition over inheritance, a deep hierachy is
often not the right apporach.

【在 l**********o 的大作中提到】
: 我现在有一个比较大的class structure大致是这样的
: A (abc)
: |
: B
: / \
: C D
: / \ |
: E F G
: / \ |
: H I J

l**********o
发帖数: 22
3
thanks for the reply!
Do you mean extend just from each level? Say newB class extends from B',
then new C class extends from C'? then the relation between newB and newC is
broken.
How to re-composition deep hierachy? Could you please give me a simple
example, is there any good method other than if-else? thanks

【在 g*****g 的大作中提到】
: Pull out the similar functions from the class hierachy, call it
: A', B', C' etc. Let B and your new class extends B'.
: Also consider composition over inheritance, a deep hierachy is
: often not the right apporach.

1 (共1页)
进入Programming版参与讨论
相关主题
问一下这个cast在java里是怎么work的friend function 不能virtual 怎么搞呢?
C++ 弱问一个请问c++中操作符可以声明为虚函数吗?
pointer to class, which class?弱问一个virtual function的问题
pointer to base class = new derived, what will happend??一个inheritance 的问题
C++ virtual function 定义在 derived class 会怎么样?c++ question, thanks
请问C++小白问题[合集] protected inheritance in C++
C++ private inheritance. v.s. compositionHow to understand the answer.
问一个inheritance的初级问题什么地方用到 Private inheritance
相关话题的讨论汇总
话题: class话题: new话题: function话题: hierachy话题: 一样