关于观察者模式的查询 [英] Query Regarding Observer Pattern
本文介绍了关于观察者模式的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hallo Rahul Rajat Singh,
我对C ++中的观察者模式有一个小问题。
不是
>
class ASubject
{
// 让我们跟踪我们观察到的所有商店
std :: vector< iobserver *>列表;
public :
void Attach(IObserver * product);
void 分离(IObserver * product);
void 通知( float 价格);
};
和商店应该从IObserver公开派生?
class 购物: public IObserver
{
// 商店名称
std :: string name;
float 价格;
public :
Shop(std :: string n);
void 更新( float 价格);
~Shop(){std :: cout<< In~Shop()<< \ n;}
};
解决方案
如果有任何问题的Rahul Rajat Singh [ ^ ],请张贴在留言板上他的文章 [ ^ ](在页面底部)。
Hallo Rahul Rajat Singh,
I have small question regarding Observer Pattern in C++.
Isn't it the
class ASubject
{
//Lets keep a track of all the shops we have observing
std::vector<iobserver*> list;
public:
void Attach(IObserver *product);
void Detach(IObserver *product);
void Notify(float price);
};
and Shop should be publicly derived from IObserver ?
class Shop : public IObserver
{
//Name of the Shop
std::string name;
float price;
public:
Shop(std::string n);
void Update(float price);
~Shop() { std::cout << " In ~Shop()" << "\n";}
};
解决方案
If you have any question to Rahul Rajat Singh[^], please post it in message board to His article[^] (on bottom of page).
这篇关于关于观察者模式的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文