Quote:
Originally Posted by jreneew2
For example, lets say I want to open and close a solenoid. Should I make a command that opens it, and a command that closes it, or just have a single command that gets passed a value to tell which valve I want to open?
|
I think it makes more sense to have a single command. The way we threw together commands like this was something like
Code:
class SomethingToggleCommand: CommandBase {
int m_mode;
public:
SomethingToggleCommand(){ // default action: toggle
m_mode = 2;
}
SomethingToggleCommand(bool isOpen){ // explicitly set open or closed
m_mode = isOpen;
}
void Execute(){
if(m_mode == 2) {
somethingSubsystem->setSomething(!somethingSubsystem->isSomethingOpen());
} else {
somethingSubsystem->setSomething(m_mode);
}
}
bool IsFinished(){
return true;
}
// etc
}
I don't think it's the
best way in terms of design, but it works ¯\_(ツ)_/¯