由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个题目 C++
相关主题
C++里面能否检测一个虚函数是否被重载?c vs c++
Tricky Pointer Problems -- Which level are you?[合集] Google C++ Coding Standard
A C++ runtime type casting questionC++0x
c++里如何判断是哪种object?说几个backend从C++导向Java的知名公司吧
pointer to class, which class?C++学到什么程度能找到初级工作
相关话题的讨论汇总
话题: appliance话题: appliances话题: off话题: oven话题: rtti
进入JobHunting版参与讨论
1 (共1页)
J*****n
发帖数: 4859
1
A power switch is required that can turn on or off any number of appliances.
An appliance is, for example, a Blender, a Toaster, or an Oven.
Other programmers have already written those appliances and you can't change
their source code. For example, you cannot require them all to implement a
particular interface.
Fortunately, each such appliance already has two methods to turn its
particular appliance on and off.
Unfortunately, all such methods were written by different people and have
different names (e.g. Blender.swizzle(), Toaster.startToasting(), Oven.
heatUp()).
-Write three third party appliances and put them in a separate package. It
should be visible from the output of each appliance whether it is turned on
or off (in its third party vocabulary).
-Make a representation of a multi-power point. You can plug in as many
appliances as you wish and turn them on and off all at once, by turning the
multi-power point on() and off().
我看了半天,觉得既然不能改已有的代码,那就只能用template + RTTI了(因为每个
class中开关的member function不是同名的,所以要知道type,才能决定调哪个函数)。
但是这样做其实很奇怪,template讲究的是compling time polymorphsim,现在加上个
RTTI(typeid),总觉得有点不伦不类的。
请教高手如何解决。
谢谢。
b*******s
发帖数: 5216
2
我觉得是在考design patterns
写个bridge模式好了,或者好像有个pattern叫specification pattern
我是低手,欢迎高手指正
c*e
发帖数: 15
1 (共1页)
进入JobHunting版参与讨论
相关主题
pointer to class, which class?C++学到什么程度能找到初级工作
c vs c++C++里面能否检测一个虚函数是否被重载?
[合集] Google C++ Coding StandardTricky Pointer Problems -- Which level are you?
C++0xA C++ runtime type casting question
说几个backend从C++导向Java的知名公司吧c++里如何判断是哪种object?
相关话题的讨论汇总
话题: appliance话题: appliances话题: off话题: oven话题: rtti