Alternative to global enum header file?

N

Nobody

Hi All,

In my application I have the following implementation for ClassA and ClassC
invoking a call on ClassB.

void ClassA::DoSomething()
{
int value = m_pClassB->Read(enum1);
}

void ClassA::DoSomethingElse()
{
int value = m_pClassB->Read(enum2);
}

------------------------------------------------

void ClassC::DoSomethingElseAgain()
{
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top