avatar
k*p
1
Sorry can't type Chinese.
One abstract class has many derived classes in different files. Each time
adding new pure virtual member functions to the abstract class will require
modifying all classes.How to change the hierachy so that only one file needs
to be modified?
Of course, you can put the new function in a file within which the behavior
is determined by object type. Is there more elegant way doing this?
Thanks!
avatar
g*k
2
Even pure virtual member function can have default implementation.
I'm confused with your alternative solution, what do you mean put the new
function in a file?

require
needs
behavior

【在 k*p 的大作中提到】
: Sorry can't type Chinese.
: One abstract class has many derived classes in different files. Each time
: adding new pure virtual member functions to the abstract class will require
: modifying all classes.How to change the hierachy so that only one file needs
: to be modified?
: Of course, you can put the new function in a file within which the behavior
: is determined by object type. Is there more elegant way doing this?
: Thanks!

avatar
b*y
3
pure virtual function does not have body and implementation

【在 g*****k 的大作中提到】
: Even pure virtual member function can have default implementation.
: I'm confused with your alternative solution, what do you mean put the new
: function in a file?
:
: require
: needs
: behavior

avatar
g*k
4
you better read the text again

【在 b*******y 的大作中提到】
: pure virtual function does not have body and implementation
avatar
k*p
5
For example, a furniture class with many pure virtual functions. Table class
and sofa class inherit it. One day,one wants to add takeapart function to
it. Instead of modifying every file, one can use if statement in a separate
file to do specific work depending on object type. This may violate
encapsulation, which is fine in this problem. I don't think pure virtual
function can have body.

【在 g*****k 的大作中提到】
: Even pure virtual member function can have default implementation.
: I'm confused with your alternative solution, what do you mean put the new
: function in a file?
:
: require
: needs
: behavior

avatar
m*g
6
Pure virtual destructor needs a body
avatar
g*k
7
pure virtual function doesn't require to have body, but it can have
definition.
When you make the decision to add the pure virtual function, you already
force
each derived class to implement its own function. So no matther how many
derived
classes you have, you have to modify them.

class
separate

【在 k*p 的大作中提到】
: For example, a furniture class with many pure virtual functions. Table class
: and sofa class inherit it. One day,one wants to add takeapart function to
: it. Instead of modifying every file, one can use if statement in a separate
: file to do specific work depending on object type. This may violate
: encapsulation, which is fine in this problem. I don't think pure virtual
: function can have body.

avatar
s*n
8
why do you need pure virtual functions? use a strategy or delegate as a
member of the abstract class. ctor different class with different delegates.
abc of design pattern books.

class
separate

【在 k*p 的大作中提到】
: For example, a furniture class with many pure virtual functions. Table class
: and sofa class inherit it. One day,one wants to add takeapart function to
: it. Instead of modifying every file, one can use if statement in a separate
: file to do specific work depending on object type. This may violate
: encapsulation, which is fine in this problem. I don't think pure virtual
: function can have body.

avatar
s*x
9
i believe visitor design patten should be the right answer.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。