Couple of ways, one way is to do the following :
//interface
struct Conditional{
virtual bool preCondition()const=0;
virtual bool postCondition()const=0;
};
//adapter for default
struct ConditionalTrueAdapter: Conditional{
bool preCondition()const{return true;}
bool postCondition()const{return true;}
};
//interface
struct Command{
virtual void execute()=0;
};
class PauseGameCommand : public Command{
private:
Conditional condition;
public:
PauseGameCommand(const Conditional& c = ConditionalTrueAdapter())
: condition(c){}
void execute(){
assert(p.preCondition());
/* code to pause game goes here */
assert(p.postCondition());
}
};
Use it like so :
if(user.clickedPauseGame()){
PauseGameCommand();
}
else if(user.clickedExitGame()){
Conditional c = GameState.getGameCondition();
PauseGameCommand(c); // for example, say, preCondition checks if it can be paused, and postCondition checks if everything went well
}