I have a C++ base code using GOF observer pattern, and I need a UI object, written in C#, act as an observer. I'd like to use C++ Interop as a wrapper, and let C# object inherit the IObserver which is written in C++, but it seems that C++ Interop cannot do it.
Here's the code in C++,
class IObserver
{
public:
virtual void Update(void* pSender, int arg) = 0;
};
class ISubject
{
public:
virtual void RegisterObserver(IObserver* pObserver) = 0;
virtual void RemoveObserver(IObserver* pObserver) = 0;
virtual void NotifyObservers(int arg) = 0;
};
// Heater is to boil water
class Heater : public ISubject
{
public:
Heater(void);
virtual ~Heater(void);
void Register(IObserver* pObserver, bool bAdd);
void BoilWater();
protected:
virtual void RegisterObserver(IObserver* pObserver);
virtual void RemoveObserver(IObserver* pObserver);
void NotifyObservers(int arg);
private:
typedef std::list<IObserver*> ObserverList;
ObserverList observers_;
};
Assume that there is a progress bar in UI. while the temperature is rising, the progress bar is running with it. How could I code it? Any advice will be greatly appreciated.