I wrote a simple observer pattern, where the observer has "void notify(std::string)" function and the observable object calls it on every registered observer and uses tokenized string to transfer the data. This is very simple, easy and works, but I need to go step forward.
I need to implement it with signal and slots (for example using boost::signals2). However I don't know how exactly slot and signals should look like and how they should be placed. I also have no idea how to allow registering whatever function I want and not only void (string).
I couldn't find any good resource which uses signals and slots for this pattern. Yet everyone says that signals and slots are amazing for observer pattern. Could you guide me how should signals and slots be used for the observer pattern?
My current implementation without signals is as follows:
class observable
{
public:
void register(observer *);
void unregister(observer *);
protected:
void notifyObservers()
{
for every registered observer
observer.notify(std::string tokenized_string);
}
}
class observer
{
public:
void notify(std::string) = 0;
}
I need to change this pattern to use signals and slots but I have no idea how it should like to be useful and well-designed and flexible.