Command Design Pattern

Command Design Pattern

This article describes the Command design pattern. This is a behavioral design pattern, a category of design pattern used by software engineers, when writing computer programs.


The Command pattern is a design pattern, used in software engineering, to encapsulate everything that is needed to execute a method at a later time. The three main concepts in this pattern are client, invoker and receiver. Firstly the client defines the command and it's properties. It is then called by invoker and sent to the receiver, which takes the properties and performs it's actions based on them.

It is defined as a behavioral design pattern because it affects program execution.


The command pattern allows developers to construct a unified message structure to encapsulate a method into a delegate, which can be resused by different owners, with different parameters.

Examples of the pattern

Commands can be used to build a history of actions, to enable record a macro, enable an undo function, or list of "roll-back" transactions.

Messages can also inform progress bars or wizards.

Commands are also useful across threads and in parallel processing in general.

In WPF, commanding allows the developer to separate the semantics of the operation, from the logic that executes the command. Examples are Print, Copy and Paste. These commands are already baked into WPF and available to use, but the implementation of the command is down to the application (Copy text, or copy a class. Print to file, or print to printer). Commands implement the ICommand interface, which also defines CanExecute and Execute delegates, to determine if the command can be executed, and what method is called upon execution. When a command is tied to a button, the CanExecute method controls the 'enabled' state of the button.

Read more and download the sample from here

Return to Top

See Also

Link to domain parent articles and related articles in TechNet Wiki.



Return to Top

Community Resources

These are the external links, including links to Microsoft and TechNet sites that are non-Wiki



Return to Top

References section

Use this section if you pulled source material and ideas from other sites, blogs, or forums. Make sure you have permission from authors to use their material.




Return to Top

Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
  • XAML guy edited Revision 1. Comment: tweak

  • XAML guy edited Original. Comment: tidied sections

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Page 1 of 1 (3 items)