I have an enum with some states in it:
enum State
{
A,
B,
C,
D
}
and an object that has a corresponding state:
class MyObject
{
State state;
}
I need to write an algorithm that takes two MyObject instances and does something depending on the particular states of those instances:
void doWork(MyObject o1, MyObject o2)
{
if (o1.state == A && o2.state == A)
{
// do something
}
else if (o1.state == A && o2.state == B)
{}
// etc for all combinations...
}
Obviously this approach has many problems and I would like to change it to ideally get rid of the if/else statement.
Is there any pattern for such a requirement?
Thanks