Вот я и в раздумьях, а мож выкинуть вовсе неактуальный для канадских С++ программистов-гуистов вопрос об имплементации CPubliher/CSubscriber. Там, конечно, всё просто имплементровано. Ну, не видел, чтобы кто-то реально это делал для построения объектно-ориентированной модели ГУИ(себя драгоценного я не учитываю

Классы там приблизительно такие (это одна из первых имплементаций):
Код: Выделить всё
#define IDO_ALL 0 // send message to all objects
#define afxtempl // use MFC templated collection classes
#ifdef afxtempl
#include <afxtempl.h>
#endif
/////////////////////////////////////////////////////////////////////////////
// forward declarations
class CCustomSubscriber;
class CSubscriber;
class CCustomPublisher;
class CPublisher;
/////////////////////////////////////////////////////////////////////////////
// CCustomCommand class
class CCustomCommand {
public:
CCustomSubscriber* Sender; // Source
UINT SenderID;
CCustomSubscriber* Rcpt; // Destination
UINT RcptID;
CCustomCommand (UINT _RcptID = IDO_ALL)
{
memset(this, 0 ,sizeof(CCustomCommand));
RcptID = _RcptID;
}
};
/////////////////////////////////////////////////////////////////////////////
//
// CCustomSubscriber class
//
/////////////////////////////////////////////////////////////////////////////
class CCustomSubscriber {
public:
// Publisher event handling
virtual void OnKillPublisher (void);
virtual bool OnRegistering (CCustomPublisher * pPublisher);
virtual bool OnRegistered (CCustomPublisher * pPublisher);
virtual bool OnUnRegistering (void);
virtual bool OnUnRegistered (void);
virtual void* OnGetInterface (LPCTSTR InterfaceName);
virtual void OnPush (const CCustomCommand* pCommand) = 0;
UINT get_ID (void) {return m_ID;}
private:
UINT m_ID; // user symb.const. for the registered object
CCustomPublisher* m_pPublisher; // own publisher
// CCustomSubscriber interface
protected:
CCustomSubscriber(): m_pPublisher(NULL), m_ID(0L), rcRegistration(false){}
~CCustomSubscriber () { _SelfUnRegister(); }
bool rcRegistration;
// Properties
void set_ID (UINT ID_OBJ) { m_ID = ID_OBJ; }
CCustomPublisher* get_Publisher (void) { return m_pPublisher; }
void set_Publisher (CCustomPublisher* pPublisher) { m_pPublisher = pPublisher; }
CCustomSubscriber* get_Self (void) { return this; }
// Methods
virtual bool _SelfRegister (CCustomPublisher* pPublisher, UINT ID_OBJ);
virtual bool _SelfUnRegister (void);
virtual void Push (CCustomCommand* pCommand);
};
/////////////////////////////////////////////////////////////////////////////
//
// CCustomPublisher class
//
/////////////////////////////////////////////////////////////////////////////
class CCustomPublisher
{
private:
CArray <CCustomSubscriber*, CCustomSubscriber*> m_aObject;
protected:
inline bool IsSubscriberRegistered (CCustomSubscriber* pSubscriber);
inline CCustomSubscriber* GetSubscriber(UINT ID_OBJ);
inline bool IsIDRegistered (CCustomSubscriber* pSubscriber);
public:
CCustomPublisher() {}
~CCustomPublisher()
{
for (int i = 0; i < m_aObject.GetSize(); i++)
m_aObject.GetAt(i)->OnKillPublisher();
}
virtual bool GetSubscriberInterface (UINT ID_OBJ, LPCTSTR InterfaceName, void ** ppvInterface);
virtual bool RegisterSubscriber (CCustomSubscriber* pSubscriber);
virtual bool UnRegisterSubscriber (CCustomSubscriber* pSubscriber);
virtual void Publish (CCustomCommand* pCommand);
};
/////////////////////////////////////////////////////////////////////////////
//
// CPubliher/CSubscriber classes
//
/////////////////////////////////////////////////////////////////////////////
class CPublisher : protected CCustomPublisher
{
protected:
CPublisher() {}
CCustomPublisher::GetSubscriberInterface;
public:
CCustomPublisher::Publish;
};
//----------------------------------------------------------------------------
class CSubscriber: protected CCustomSubscriber {
protected:
virtual bool OnRegistering(CCustomPublisher * pPublisher)
{// Permit single registration only
return rcRegistration = ( get_Publisher () )? false : true;
}
// OR Permit unregistration and re-registration only
//virtual bool OnRegistered(CCustomPublisher* pPublisher)
//{
// CCustomPublisher* m_pPublisher = get_Publisher();
// if (m_pPublisher && (m_pPublisher != pPublisher)) m_pPublisher->UnRegisterSubscriber(this);
// set_Publisher( pPublisher ); // than apply registration
// return rcRegistration = true;
//}
///////////////////////////////////////////////////////////////////////////
// CSubscriber interface
CSubscriber() {}
CSubscriber(CPublisher* pPublisher, UINT ID_OBJ) { SelfRegister(pPublisher, ID_OBJ); }
virtual bool SelfRegister(CPublisher* pPublisher, UINT ID_OBJ)
{
CCustomPublisher* pCustomPublisher = reinterpret_cast<CCustomPublisher*>(pPublisher);
return (!pCustomPublisher)? false : (CCustomSubscriber::_SelfRegister(pCustomPublisher, ID_OBJ));
}
};
Так вот, братцы, может, и правда это всё ламерство убрать из резюме


Спасибо.