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.

December 25, 2009

Factory Method

Filed under: Design Patterns, OOP — Tags: , — iBen @ 7:19 am

The factory method is a simple concept to grasp, but not as easy a task to understand why to use it.
The factory method Pattern, is dubbed such that a subclass will override the method of its superclass.

This means the super class is in charge of crafting the signature of the method that the subclasses must adhere while the subclass implements in any way shape or form the return type its signature calls for.

FactoryMethod Design Pattern

FactoryMethod Design Pattern

At first glance, the factory method pattern appears to be a proxy to a product. But beacause you must import the Concrete Factory into your current client .as file, why would you even need to use a factory method at all?

The answer is not because its easy to update or because it separates the client from the product, although these are very accurate. Its in the way you need to see how its useful. What this did was create a second step to creating your classes, so if you were to use this concrete class in many places throughout your application, rather than hunting those instantiations down, you can go right to the 1 concrete class and make changes that are necessary.

If you used the product directly rather than the creator you would have to physically adjust each instance.

Powered by WordPress