BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Command Pattern In .NET

by Roopesh Shenoy on Apr 16, 2012 |

In Command Pattern, an object is used to represent and encapsulate all the information needed to call the method at a later time – method name, object that owns the method and values for the parameters. In the first part of an article series “The Command Pattern In .NET”, Eric Vogel walks through using the ICommand interface in the context of WPF applications.

A Command is normally an operation and a command object knows how to perform that operation. The command objects themselves implement a common interface – the invoker only needs to invoke the method by calling that interface, without knowing the implementation details. This helps in decoupling the object that invokes the operation from the one that knows how to perform it leading to clear separation of concerns.

The main purpose of using ICommand in Silverlight or WPF applications is to keep the XAML view-behind clean of any user-interaction code. The article “Using ICommand In Silverlight” is also a good read for understanding how to implement this in a Silverlight application. Since command objects can be queued for later invokation of their methods, this pattern is also quite useful in implementing Undo-Redo features.

Note that ICommand itself is not necessary for implementing Command Pattern – you could create your own interface or an abstract class for defining what a Command is. These samples show the command pattern in action without relying on the ICommand interface but using the same underlying concept. 

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT