Hi,
I have a Blackboard object which is a singleton, what it does is store the message and the reciever. The challenge is that the blackboard will send an alert to the reciever and the reciever have to check the blackboard for the message.
class Subscriber{
public:
virtual ~Subscriber() {}
virtual void update() {}
virtual void alert(){ newMessage = true; }
virtual void noMessage(){ newMessage = false; }
private:
std::string message;
bool newMessage;
};
class Blackboard{
public:
static Blackboard* getInstance();
~Blackboard(){}
void subscribe(Subscriber* s){ subscribers.push_back(s); }
void unSubscribe(Subscriber* s){ subscribers.remove(s); }
void post(std::string msg, Subscriber* toWhom);
void notify(Subscriber* s);
void notifyAll();
private:
Blackboard(): message(""){}
std::string message;
std::list<Subscriber*> subscribers;
static Blackboard* instance;
I cant use toWhom->update()
, I know i can do it this way inside post()
method. The thing is: I need to use alert()
. I cant explain it well but all the blackboard do is notify its subscriber and the subscriber will have to check the blackboard when notified then the subscriber will act based on the message. I cant think of a way on how to do this.