This article and the author of the original text has a certain deviation, which added a part of the personal view, please check the author's original text. ***
Original Connection Http://www.dofactory.com/Patterns/PatternCommand.aspx
Command mode intent:
GOF in the Book of Design Patterns: "Encapsulate a request as an object so that you can parameterize the client with different requests, queue or log request logs for requests, and support actions that can be canceled." "Different requests" here also mean that the request may change, is a possible extension of the function point.
command-mode UML diagram:
Command mode encapsulates a request into an object so that you can parameterize the customer with different requests.
Simple example: Client
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace designpattern.command
6{
7 class program
8 {
9 static void Main (string[] args)
1 0 {
11//Create Receiver, command and invoker
Receiver Receiver = new Receiver ();
14//According to polymorphism, the parent class reference points to the Subclass Object
Command command = new Concretecommand (receiver);
Invoker invoker = new Invoker ();
18//Set and Execute command
invoker. SetCommand (command);
Invoker. ExecuteCommand ();
Console.read ();
}
26