N
Nobody
Hi All,
In my application I have the following implementation for ClassA and ClassC
invoking a call on ClassB.
void ClassA:oSomething()
{
int value = m_pClassB->Read(enum1);
}
void ClassA:oSomethingElse()
{
int value = m_pClassB->Read(enum2);
}
------------------------------------------------
void ClassC:oSomethingElseAgain()
{
int value = m_pClassB->Read(enum3);
}
------------------------------------------------
int ClassB::Read(enum tag enumValue)
{
switch (enumValue)
{
case enum1:
// invoke a call on ClassX, do something and return an int
case enum2:
// invoke a call on ClassY, do something different and return
an int
case enum3:
// invoke a call on ClassZ, do something different again and
return an int
)
}
------------------------------------------------
Some other details:
The enums are defined in a header file that is accessible to ClassA, ClassB
and ClassC.
ClassB is derived from an abstract base class.
ClassB uses the id parameter to determine which operation to call on which
class. I think this might be a use of the Facade pattern.
I come form a C background and am relatively new to OO and C++.
Although this works fine, this mechanism exists throughout the application
for other interfaces and I feel that there is some elegant way of doing this
that I have missed.
Is there a better way to implement this or am I OK with what I've got?
Specifically an alternative to the use of the enum header file and the
switch statement.
I would like to keep the abstract base class and the idea of a message id to
give to ClassB so that it knows which class the Read() is for when invoked
by ClassA or ClassC.
Thanks
In my application I have the following implementation for ClassA and ClassC
invoking a call on ClassB.
void ClassA:oSomething()
{
int value = m_pClassB->Read(enum1);
}
void ClassA:oSomethingElse()
{
int value = m_pClassB->Read(enum2);
}
------------------------------------------------
void ClassC:oSomethingElseAgain()
{
int value = m_pClassB->Read(enum3);
}
------------------------------------------------
int ClassB::Read(enum tag enumValue)
{
switch (enumValue)
{
case enum1:
// invoke a call on ClassX, do something and return an int
case enum2:
// invoke a call on ClassY, do something different and return
an int
case enum3:
// invoke a call on ClassZ, do something different again and
return an int
)
}
------------------------------------------------
Some other details:
The enums are defined in a header file that is accessible to ClassA, ClassB
and ClassC.
ClassB is derived from an abstract base class.
ClassB uses the id parameter to determine which operation to call on which
class. I think this might be a use of the Facade pattern.
I come form a C background and am relatively new to OO and C++.
Although this works fine, this mechanism exists throughout the application
for other interfaces and I feel that there is some elegant way of doing this
that I have missed.
Is there a better way to implement this or am I OK with what I've got?
Specifically an alternative to the use of the enum header file and the
switch statement.
I would like to keep the abstract base class and the idea of a message id to
give to ClassB so that it knows which class the Read() is for when invoked
by ClassA or ClassC.
Thanks