Your design suffers from the fact that it is easy to be in poor condition (for example, that, if both stop_and play_are true?
enum , 1 .
++ enum Swift, Java # enum: - , #define.
++ 11 enum class, # enum. , Java Swift enum s.
- :
enum class PlayerState {
Stopped,
Playing,
Paused
}
Reset , , enum.
class VideoPlayer {
private:
PlayerState state;
public:
VideoPlayer() :
state( PlayerState::Stopped )
{
}
void play() {
switch( this->state ) {
case PlayerState::Stopped:
this->state = PlayerState.Playing;
break;
case PlayerState::Playing:
throw VideoPlayerStateExeception("Already playing");
case PlayerState::Paused:
this->resume();
break;
}
}
}