January 3, 2010

Command Pattern

Filed under: Design Patterns, OOP — Tags: , , — iBen @ 1:34 am

The Command Pattern, is a very useful pattern when wanting a client to call a method of an object but keep all information of that particular object not only hidden but interchangeable with other objects.

The way the command pattern hides the information regarding the target is by delegating to the wrapped object within.

a Command Abstract defines the structure for all subclasses Commands.

public class aCommand{

private var _targetObject:Object

public function aCommand(obj:Object):void{

public function execute():void{
//throw new IllegalOperationError(’Abstract methods must be overriden’)

When a subclass of aCommand are created, an object that will be the target which a method will be called upon will be delegated to when a client calls the execute().

Its the concrete class of the aCommand which will hold specifics about the method it will trigger.

By delegating to the method from within a type aCommand, the only thing that our client must know is that there is a type aCommand which it must call execute upon.

The command pattern utilizes strategy method to be interchangeable by declaring a type of aCommand and delegates through composition to a receiver.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress