Design mode 12-command mode

Source: Internet
Author: User

Command mode: Encapsulate the request, parameterize the client with different requests, queue the request or log the request, and revoke the operation.

1 namespacedesignmodel. Command mode2 {3     Abstract classCommand4     {5         protectedexecer exe;6          PublicCommand (execer execer)7         {8              This. exe =Execer;9         }Ten         Abstract  Public voidexeccommand (); One     } A  -     classCommandone:command -     { the          PublicCommandone (Execer execer):Base(execer) {} -          Public Override voidexeccommand () -         { - exe. Execcommandone (); +         } -     } +     classCommandtwo:command A     { at          PublicCommandtwo (Execer execer):Base(execer) {} -          Public Override voidExecCommand () =exe. Execcommandtwo (); -  -     } -  -     classExecer in     { -          Public voidExeccommandone () = Console.WriteLine (""); to          Public voidExeccommandtwo () = Console.WriteLine (""); +      } -  the  *     classBuilder $     {Panax Notoginsengilist<command> list =NewList<command>(); -          PublicBuilder setbuilder (Command command) the         { + list. ADD (command); A             return  This; the         } +          Public voidRemove (Command command) -         { $ list. Remove (command); $         } -          Public voidNotify () -         { theList. All (x = {X.execcommand ();return true; }); -         }Wuyi     } the } -  Static voidCommand mode () Wu         { -Execer Execer =Newexecer (); AboutCommand C1 =NewCommandone (execer); $Command C2 =NewCommandtwo (execer); -             varBuilder =Newdesignmodel. Command mode. Builder (); - Builder. Setbuilder (C1). Setbuilder (C2). Notify (); -}
View Code

Advantages:

1 command queue can be designed;

2 allow the command receiver to veto the command;

3 Adding a specific command class does not affect other parts.

Design mode 12-command mode

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.