BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Command Pattern In .NET

| by Roopesh Shenoy Follow 0 Followers on Apr 16, 2012. Estimated reading time: 1 minute |

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. 

Rate this Article

Adoption Stage
Style

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

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT