I can't help you with example link, but can provide example by myself.
1) Define ICommand interface:
public interface ICommand {
void Do();
void Undo();
}
2) Do your ICommand implementations for concrete commands, but also define abstract base class for them:
public abstract class WinFormCommand : ICommand {
}
3) Create command invoker:
public interface ICommandInvoker {
void Invoke(ICommand command);
void ReDo();
void UnDo();
}
public interface ICommandDirector {
void Enable(ICommand);
void Disable(ICommand);
}
public class WinFormsCommandInvoker : ICommandInvoker, ICommandDirector {
private readonly Dictionary _commands;
private readonly Queue _commandsQueue;
private readonly IButtonDirector _buttonDirector;
// you can define additional queue for support of ReDo operation
public WinFormsCommandInvoker(ICommandsBuilder builder, IButtonDirector buttonDirector) {
_commands = builder.Build();
_buttonDirector = buttonDirector;
_commandsQueue = new Queue();
}
public void Invoke(ICommand command) {
command.Do();
__commandsQueue.Enqueue(command);
}
public void ReDo() {
//you can implement this using additional queue
}
public void UnDo() {
var command = __commandsQueue.Dequeue();
command.Undo();
}
public void Enable(ICommand command) {
_commands.[command] = true;
_buttonDirector.Enable(command);
}
public void Disable(ICommand command) {
_commands.[command] = false;
_buttonDirector.Disable(command);
}
}
4) Now you can implement your ICommandsBuilder, IButtonDirector and add other interfaces such as ICheckBoxDirector to WinFormsCommandInvoker.