k*p 发帖数: 1526 | 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! |
g*****k 发帖数: 623 | 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!
|
b*******y 发帖数: 1240 | 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
|
g*****k 发帖数: 623 | 4 you better read the text again
【在 b*******y 的大作中提到】 : pure virtual function does not have body and implementation
|
k*p 发帖数: 1526 | 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
|
m*********g 发帖数: 646 | 6 Pure virtual destructor needs a body |
g*****k 发帖数: 623 | 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.
|
s*****n 发帖数: 5488 | 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.
|
s**x 发帖数: 7506 | 9 i believe visitor design patten should be the right answer. |