Is switch-case over enumeration bad practice?
Posted
by
Puckl
on Programmers
See other posts from Programmers
or by Puckl
Published on 2012-09-22T12:36:26Z
Indexed on
2012/09/22
15:48 UTC
Read the original article
Hit count: 358
I have an enumeration with the commands Play
, Stop
and Pause
for a media player. In two classes I do a switch-case over the received commands. The player runs in a different thread and I deliver the commands in a command queue to the thread.
If I generate class diagrams the enumeration has dependencies all over the place. Is there a nicer way to deal with the commands? If I would change/extend the enumeration, I would have to change several classes. (Its not super important to keep the player extensible, but I try to write nice software.)
© Programmers or respective owner