由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - A design question
相关主题
Can we define pure virtual function?请教template class怎么处理Inheritance问题(面试题)
各位总结一下区别:virtual function and virtual destructor?贡献点g家电面题
C++ Q60 calling virtual function in constructor (JPMorgan)问个C++ virtual function的问题
C++ online Test 一题virtual function的问题
分享两道面试题--求教高手BB家电面
abstraction vs encapsulation问一道inline function的题目
abstract class must have a pure virtual function?现在招个会C++的人真难
问几个跟C++有关的面试题一道面试的选择题
相关话题的讨论汇总
话题: pure话题: virtual话题: class话题: function话题: file
进入JobHunting版参与讨论
1 (共1页)
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.
1 (共1页)
进入JobHunting版参与讨论
相关主题
一道面试的选择题分享两道面试题--求教高手
Amazon第一轮电面面经abstraction vs encapsulation
OO - design questionsabstract class must have a pure virtual function?
怎么准备OO Design问几个跟C++有关的面试题
Can we define pure virtual function?请教template class怎么处理Inheritance问题(面试题)
各位总结一下区别:virtual function and virtual destructor?贡献点g家电面题
C++ Q60 calling virtual function in constructor (JPMorgan)问个C++ virtual function的问题
C++ online Test 一题virtual function的问题
相关话题的讨论汇总
话题: pure话题: virtual话题: class话题: function话题: file