Real OOPers do not use if ! Prefer polymorphism to conventions.
Of course, there may be situations where enum is the way to go (say, if you have very, very many states or you know that it is very likely for a domain that all observers will be interested in all transitions), but in the general case the first option is less complicated . Using the second approach, each listener must repeat the same piece of code:
if (theStateImInterestedIn == event.stateType){ }
And each listener needs this, except for listeners who also respond to all transitions! Code duplication! Aaaaargh! As we all know, the repeated code causes errors (hence the DRY principle ), and therefore we can conclude that your gut feeling is correct - the first option (using two different classes) is better, since each individual implementation of the receiver will have a smaller boiler plate.
Also; add else , and you have interesting moments when you add a new state: some listeners were interested in both types of events and therefore assumed that the else branch means "state in which I did not check in if ". Now they are broken because the else clause spans state> 1.
source share