Example: Implementing methods from the Command interface
The Command interface declares two methods, isReadyToCallExecute and reset, that the application programmer must implement.
Methods from the Command interface in the ModifyCheckingAccountCmdImpl class
The following code example shows the implementations for the ModifyCheckingAccountCmd command. The implementation of the isReadyToCallExecute method ensures that the checkingAccount variable is set. The reset method sets all of the variables back to starting values.
... public class ModifyCheckingAccountCmdImpl extends TargetableCommandImpl implements ModifyCheckingAccountCmd { ... // Methods from the Command interface public boolean isReadyToCallExecute() { if (checkingAccount != null) return true; else return false; } public void reset() { amount = 0; balance = 0; oldBalance = 0; checkingAccount = null; targetPolicy = new TargetPolicyDefault(); } ... }
Related tasks
Implementing command interfaces
Reference topic