System Commander
2010
![]() |
![]() System Commander 90 Professional PC XP VISTA 7 NEW $8.12 Time Remaining: 23d 14h 3m Buy It Now for only: $8.12 |
![]() System Commander 90 Professional PC XP VISTA 7 NEW $8.69 Time Remaining: 13h 16m Buy It Now for only: $9.99 |
![]() SYSTEM COMMANDER 90 PRO PC OS MANAGER BRAND NEW $10.10 Time Remaining: 8d 23h 59m Buy It Now for only: $10.10 |
![]() System Commander Software Run More Than One Operating System New Sealed $9.99 Time Remaining: 3d 11h 9m |
![]() System Commander 9 Professional Version 90 PC Utilities $12.99 Time Remaining: 27d 3h 32m Buy It Now for only: $12.99 |
![]() System Commander 9 Run Multiple Operating Systems on Your PC SoftwareSALE $11.95 Time Remaining: 14d 7h 39m Buy It Now for only: $11.95 |
![]() System Commander 9 Professional Version 90 PC Utilities $9.99 Time Remaining: 4d 13h 27m Buy It Now for only: $12.49 |
![]() System Commander 9 Pro Multiple OS Linux+Solaris PC NEW $20.32 Time Remaining: 22d 9h 25m Buy It Now for only: $20.32 |
System Commander

Command Design Pattern
Command pattern is a separation of following paticipants to carry out some task:
Client - Who wants the task done (our program, like main(...) method)
Invoker - Who initiates a task
Receiver - Who listenes to the command and carries out the task.
Command - interface for execution between invoker and receiver.
ConcreteCommand - implementation of Command. Holds the parameters required to carry out the operation.
Now look at the code snippet below( taken from GOF http://www.dofactory.com/Patterns/PatternCommand.aspx)
// Command pattern -- Real World example
using System;
using System.Collections;
namespace DoFactory.GangOfFour.Command.RealWorld
{
// MainApp test application
class MainApp
{
static void Main()
{
// Create user and let her compute
User user = new User();
user.Compute('+', 100);
user.Compute('-', 50);
user.Compute('*', 10);
user.Compute('/', 2);
// Undo 4 commands
user.Undo(4);
// Redo 3 commands
user.Redo(3);
// Wait for user
Console.Read();
}
}
// "Command"
abstract class Command
{
public abstract void Execute();
public abstract void UnExecute();
}
// "ConcreteCommand"
class CalculatorCommand : Command
{
char @operator;
int operand;
Calculator calculator;
// Constructor
public CalculatorCommand(Calculator calculator,
char @operator, int operand)
{
this.calculator = calculator;
this.@operator = @operator;
this.operand = operand;
}
public char Operator
{
set{ @operator = value; }
}
public int Operand
{
set{ operand = value; }
}
public override void Execute()
{
calculator.Operation(@operator, operand);
}
public override void UnExecute()
{
calculator.Operation(Undo(@operator), operand);
}
// Private helper function
private char Undo(char @operator)
{
char undo;
switch(@operator)
{
case '+': undo = '-'; break;
case '-': undo = '+'; break;
case '*': undo = '/'; break;
case '/': undo = '*'; break;
default : undo = ' '; break;
}
return undo;
}
}
// "Receiver"
class Calculator
{
private int curr = 0;
public void Operation(char @operator, int operand)
{
switch(@operator)
{
case '+': curr += operand; break;
case '-': curr -= operand; break;
case '*': curr *= operand; break;
case '/': curr /= operand; break;
}
Console.WriteLine(
"Current value = {0,3} (following {1} {2})",
curr, @operator, operand);
}
}
// "Invoker"
class User
{
// Initializers
private Calculator calculator = new Calculator();
private ArrayList commands = new ArrayList();
private int current = 0;
public void Redo(int levels)
{
Console.WriteLine("n---- Redo {0} levels ", levels);
// Perform redo operations
for (int i = 0; i {
if (current {
Command command = commands[current++] as Command;
command.Execute();
}
}
}
public void Undo(int levels)
{
Console.WriteLine("n---- Undo {0} levels ", levels);
// Perform undo operations
for (int i = 0; i {
if (current > 0)
{
Command command = commands[--current] as Command;
command.UnExecute();
}
}
}
public void Compute(char @operator, int operand)
{
// Create command operation and execute it
Command command = new CalculatorCommand(
calculator, @operator, operand);
command.Execute();
// Add command to undo list
commands.Add(command);
current++;
}
}
}
Here Main(...) is the client
Client asks User (Invoker) to carry out some task (Calculations by Compute(...) method)
User knows about Calculator (Receiver) who will do the calculation and command which is an interface to call the required calculation operation (Execute or Unexecute).
But what calculation is to be done is known to Client. Client asks (or issues commands) User to do some +, - , *, / operations.
User records these commands in an array and calls command.Execute or UnExecute. the implementation(CalculatorCommand) knows well how to do the opertaion.
* Now here comes the use of command. If there is need to undo upto some level, user has a record of what commands were issued. It will just call the receiver (CalculatorCommand) to carry out same commands in reverse.
Uses for the Command pattern
Command objects are useful for implementing:
Multi-level undo: If all user actions in a program are implemented as command objects, the program can keep a stack of the most recently executed commands. When the user wants to undo a command, the program simply pops the most recent command object and executes its undo() method.
Transactional behavior Undo is perhaps even more essential when it's called rollback and happens automatically when an operation fails partway through. Installers need this and so do databases. Command objects can also be used to implement two-phase commit.
Progress bars Suppose a program has a sequence of commands that it executes in order. If each command object has a getEstimatedDuration() method, the program can easily estimate the total duration. It can show a progress bar that meaningfully reflects how close the program is to completing all the tasks.
Wizards Often a wizard presents several pages of configuration for a single action that happens only when the user clicks the "Finish" button on the last page. In these cases, a natural way to separate user interface code from application code is to implement the wizard using a command object. The command object is created when the wizard is first displayed. Each wizard page stores its GUI changes in the command object, so the object is populated as the user progresses. "Finish" simply triggers a call to execute(). This way, the command class contains no user interface code.
GUI buttons and menu items In Swing and Borland Delphi programming, an Action is a command object. In addition to the ability to perform the desired command, an Action may have an associated icon, keyboard shortcut, tooltip text, and so on. A toolbar button or menu item component may be completely initialized using only the Action object.
Thread pools A typical, general-purpose thread pool class might have a public addTask() method that adds a work item to an internal queue of tasks waiting to be done. It maintains a pool of threads that execute commands from the queue. The items in the queue are command objects. Typically these objects implement a common interface such as java.lang.Runnable that allows the thread pool to execute the command even though the thread pool class itself was written without any knowledge of the specific tasks for which it would be used.
Macro recording If all user actions are represented by command objects, a program can record a sequence of actions simply by keeping a list of the command objects as they are executed. It can then "play back" the same actions by executing the same command objects again in sequence. If the program embeds a scripting engine, each command object can implement a toScript() method, and user actions can then be easily recorded as scripts.
Networking It is possible to send whole command objects across the network to be executed on the other machines, for example player actions in computer games.
Parallel Processing Where the commands are written as tasks to a shared resource and executed by many threads in parallel (possibly on remote machines -this variant is often referred to as the Master/Worker pattern)
Mobile Code Using languages such as Java where code can be streamed/slurped from one location to another via URLClassloaders and Codebases the commands can enable new behavior to be delivered to remote locations (EJB Command, Master Worker)
References:
GOF official site:
http://www.dofactory.com/Patterns/PatternCommand.aspx
Wikipidea
http://en.wikipedia.org/wiki/Command_pattern
About the Author
Software developer in India
Which protocol can be used in an unreliable communications system?
Two blue armies are each poised on opposite hills preparing to
attack a single red army in the valley. The red army can defeat
either of the blue armies separately but will fail to defeat both
blue armies if they attack simultaneously. The blue armies
communicate via an unreliable communications system (a foot
soldier). The commander with one of the blue armies would like to
attack at noon. His problem is this: if he sends a message to the
other blue army, ordering the attack, he cannot be sure it will
get through. He could ask for acknowledgement, but that might not
get through. Is there a protocol that the two blue armies can use
to avoid defeat?
TCP, connection oriented with acknowledgements.
Intelligent Automation - System Commander








