private static void Main() { // Application_A var service = new CustomerService(); var command = new AddCustomerCommand(service); var button = new Button(command); button.Click(); // Application_B var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); // Application_C var history = new History(); var document = new HtmlDocument { Content = "Hello World" }; var boldCommand = new BoldCommand(document, history); boldCommand.Execute(); System.Console.WriteLine(document.Content); // <b>Hello World</b> var undoCommand = new UndoCommand(history); undoCommand.Execute(); System.Console.WriteLine(document.Content); // Hello World }
static void Main(string[] args) { var history = new History(); var document = new HtmlDocument(); document.Content = "Hello World"; var boldCommand = new BoldCommand(document, history); boldCommand.Execute(); Console.WriteLine(document.Content); var undoCommand = new UndoCommand(history); undoCommand.Execute(); Console.WriteLine(document.Content); Console.ReadKey(); //TODO: add more commands here var service = new CustomerService(); var command = new AddCustomerCommand(service); var button = new Button(command); button.Click(); Console.ReadKey(); var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); Console.ReadKey(); }
static void Main(string[] args) { var addCustomerCommand = new AddCustomerCommand(new CustomerService()); var button = new Button(addCustomerCommand); button.Click(); // Because we are representing each individual task using a command object, // we can combine these commands inside a composite object and re-execute them later on. var compositeCommand = new CompositeCommand(); compositeCommand.Add(new ResizeCommand()); compositeCommand.Add(new BlackAndWhiteCommand()); compositeCommand.Execute(); var history = new Solution.UndoableCommands.History(); var htmlDocument = new HtmlDocument(); htmlDocument.Content = "Hello World!"; var boldCommand = new BoldCommand(htmlDocument, history); boldCommand.Execute(); Console.WriteLine(htmlDocument.Content); //boldCommand.Unexecute(); var undoCommand = new Solution.UndoableCommands.UndoCommand(history); undoCommand.Execute(); Console.WriteLine(htmlDocument.Content); Console.WriteLine("--- Exercise ---"); var exeHistory = new Exercise.End.History(); var videoEditor = new VideoEditor(); var setTextCommand = new SetTextCommand("Hello World!", videoEditor, exeHistory); setTextCommand.Execute(); Console.WriteLine(videoEditor.Text); //setTextCommand.Undo(); var exeUndoCommand = new Exercise.End.UndoCommand(exeHistory); exeUndoCommand.Execute(); Console.WriteLine(videoEditor.Text); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); // decoupling the customer service from the button // otherwise all code has to be retained in the button var service = new CustomerService(); var command = new AddCustomerCommand(service); var button = new Button(command); button.Click(); var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); var history = new History(); var document = new HtmlDocument { Content = "Hello World" }; var bold = new BoldCommand(document, history); bold.Execute(); Console.WriteLine(document.Content); var undoCommand = new UndoCommand(history); undoCommand.Execute(); Console.WriteLine(document.Content); }