Command Pattern Code Review
Use the Command Pattern
Code Review
- Command Pattern: Define the Pattern Interface and Command Objects
- Command Pattern: Define the Invoker and Receiver Objects
- Command Pattern: Use the Command Pattern
Code Walkthrough
The Program class creates an instance of the Page and Print command classes.
class Program
{
static void Main(string[] args)
{
ICommand paste = new Paste();
ICommand print = new Print();
Invoker document = new Invoker("Greetings");
document.ClipBoard = "Hello, everyone"; document.Execute(paste); document.Execute(print); document.Undo(paste);
document.ClipBoard = "Bonjour, mes amis"; document.Execute(paste); document.Redo(paste); document.Undo(paste);
document.ClipBoard = "Guten morgen, meine Freunde"; document.Redo(paste); document.Execute(print); document.Undo(print);
document.Log();
Console.Read(); }
Invoker document = new Invoker("Greetings");
document.ClipBoard = "Hello, everyone"; document.Execute(paste); document.Execute(print); document.Undo(paste);
document.ClipBoard = "Bonjour, mes amis"; document.Execute(paste); document.Redo(paste); document.Undo(paste);
document.ClipBoard = "Guten morgen, meine Freunde"; document.Redo(paste); document.Execute(print); document.Undo(print);
document.Log();
Console.Read(); }
An instance of the Invoker class is created and the required commands (methods) actioned.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!