|
-
February 4th, 2010, 07:02 PM
#1
Generic message factory or ...
Consider the pseudo code.
Code:
class Base_Msg {
public:
// stuff
virtual ~Base_Msg() {}
};
class X1_Msg : public Base_Msg {
public:
// stuff
};
// more Xn messages
class V1_Msg : public Base_Msg {
public:
// stuff
};
// more Vn messages
//later
class EvDelegate {
public:
virtual void Do_Work() = 0 ;
};
// from Client
class X1 : public EvDelegate {
X1_Msg x1Obj ;
public :
void ProcessMsg ( char *ptrBuf )
{
EvManager::Instance().Notify ( x1Obj ) ;
//if ( v1Obj.Get_XXX_Status () ) {
//}
}
};
// to Client
class V1 : public Listener< X1_Msg > {
V1_Msg v1Obj ;
public :
V1()
{
EvManager::Instance().Register ( X1_Msg ) ;
}
void OnEvent ( X1_Msg& x1 )
{
//if ( x1.Get_Whatever () == SOME_VALUE )
//{
// v1Obj.Set_Something_Else ( ... )
//}
}
// called from Servers
void Update ( XYZ_Status *subject )
{
// v1Obj.Set_Another_Thing ( subject->Value1 ) ;
//etc
}
};
class V2
{
V2_Msg v2Obj ;
public :
V2() {} //no need to 'Register' to any Xn message
// called from Servers
void Update ( ABC_Status *subject )
{
// v2Obj.Set_Whatever ( subject->Value1 ) ;
//etc
}
};
Incoming data (read) from 'Clients' get processed via the ProcessMsg member function within the appropriate Xn class. The registered Vn class is notified of the 'updated' Xn_Msg.
Outgoing data (writes) to Client is handled via the Vn class. Vn_Msg message updates (from Server side) occurs through the Update method.
Vn class registration is on a 'if needed' basis. For instance: The V2 class has no interest in an Xn_Msg.
At issue: An X1 class needs access to a v1Obj (V1_Msg). Here again not all Xn classes need access to Vn_Msg objects.
My current thought is to create a 'message repository' where interested Xn classes and Vn classes could query for the appropriate Xn_Msg or Vn_Msg. I've scanned the GOF for alternative patterns/ideas that would work well here but I'm at a loss. Ideas welcomed. Thanks in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|