Interpreting Design Patterns----command patterns

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.