BT

InfoQ Homepage News Command Pattern In .NET

Command Pattern In .NET

This item in japanese

Bookmarks

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
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.

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

Community comments

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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.