s*****r 发帖数: 773 | 1 看了网上的讨论, 关于amazon那道wood steel table chair furniture的题目
自己写了一个, 牛人帮我看看我是否写的有问题......
在我机器上编译通过, 运行成功.
#include
using namespace std;
class stuff {
public:
stuff() {}
virtual ~stuff() {}
virtual void info() = 0 ;
};
class table : public stuff {
public:
table() {}
~table() {}
void info() { cout<<"Table "<
};
class chair : public stuff {
public:
chair(){}
~chair(){}
void info() {cout<<"Chair"< |
m******9 发帖数: 968 | 2 我不是牛人,但是我觉得你的第一个方案写的有问题。
第2个方案是对的。
你的第2个方案写的就是一个bridge pattern |
P**********0 发帖数: 412 | 3 为什么是bridge pattern,
不应该是decorator吗?
弱人问一下。。
【在 m******9 的大作中提到】 : 我不是牛人,但是我觉得你的第一个方案写的有问题。 : 第2个方案是对的。 : 你的第2个方案写的就是一个bridge pattern
|
s*****r 发帖数: 773 | 4 请问有啥问题,谢谢.
【在 m******9 的大作中提到】 : 我不是牛人,但是我觉得你的第一个方案写的有问题。 : 第2个方案是对的。 : 你的第2个方案写的就是一个bridge pattern
|
l*****a 发帖数: 14598 | 5 1)Is it better to use statements as below:
furniture *wood_table=new table();
furniture *steel_chair=new chair();
so that u can use polymorphism here.
2) can u use materials as parameter for ctr() of furniture
and remove SetMaterials method as below:
furniture *wood_table=new table(new wood());
furniture *steel_chair=new chair(new steel());
【在 s*****r 的大作中提到】 : 请问有啥问题,谢谢.
|