This might seem like a trivial question, but I’m a bit muddled in my thinking regarding enums..
So I have a class – let’s say its called DVDPlayer – and I want to have an enum that represents whether it’s ON, OFF, or STANDBY.
So I can put the enum in the class – it doesn’t make sense outside of the class. My question is this – should the enum be public, so that other classes can query values, or should I make it private, and then have “isOn”, “isOFf” and “isStandby” methods?
The latter sounds a bit daft, but I’m unsure as to whether it’s a good idea to have the enum as public as well.
I would say it seems like a good idea to make it public. Main reason being that the application is easier to extend since you wouldn’t have to think about adding new methods each time you add a state.
If you decide to make it public, you should consider having it as top-level enum. I don’t really see why you say “it doesn’t make sense outside of the class”. I think a
DVDPlayerStatesounds like a perfectly fine public / top-level enum.