Mar 22, 2010

Facade Pattern

Facade Design Pattern

Facade is the front of a building. Technically, it is the simplified interface to a bigger and complex code. This complex code could be entire application  or some library or bunch of disconnected classes. I would say, web services are also an example Facade as they provide simple to use and platform independent APIs against complex and dependent code.

 

 

Technorati Tags: ,

Mar 19, 2009

Factory Method Pattern

As the name says, it is a pattern for mass production of similar (nearly similar) products (don't be afraid of produts, it means classes/components/objects).

In this pattern, a Client asks for a Product (e.g. some component) from Factory. Factory creates a product on request and deliver it to client. This way products can be seperated from being viewed by clients. Lets take an example:
Let's create a "Share This" functionality. This functionality is an example of factory method pattern because all share sites' buttons in your application have a common connection among them; they are to share your site on some social network. To understand this, let's have the factory architecture for this.
It can be easily understood that Share Button Factory creates all the share buttons for client and also seperate clients from products (social network buttons).

Aug 6, 2008

Command Pattern

The Command Pattern allows a client to issue requests (commands) to an object without making any assumptions about the request or the receiving object (receiver). This is done by decoupling the client from the receiver by including an invoker.


Command Interface:

package
{
    public interface ICommand
    {
        function execute ():void;
    }
}

Concrete Command:

package
{
    public class ConcreteCommand implements ICommand
    {
        var receiver:Receiver;
      
        public function ConcreteCommand (rec:Receiver):void
        {
            receiver = rec;
        }
      
        public function execute ():void;
        {
            receiver.action ();
        }
    }
}


Receiver:

package
{
    public class Receiver
    {
        public function action ()
        {
            trace ("Receiver doing action.");
        }
    }
}

Invoker:

package
{
    public class Invoker
    {
        var currentCommand:ICommand;
      
        public function setCommand (c:ICommand):void
        {
            currentCommand = c;
        }
      
        public function executeCommand ():void
        {
            currentCommand.execute ();
        }
    }
}

Client:

package
{
    import flash.display.MovieClip;
  
    public class Main
    {
        public function Main ():void
        {
            var rec:Receiver = new Receiver ();
            var concCommand:ICommand = new ConcreteCommand (rec);
            var invoker:Invoker = new Invoker ();
            invoker.setCommand (concCommand);
            concCommand.execute ();
        }
    }
}

Jul 23, 2008

Design Patterns
Creational Patterns:
  1. Factory Method Pattern
  2. Singleton Pattern
Structural Patterns:
  1. Decorator Pattern
  2. Adapter Pattern
  3. Composite Pattern
Behavioral Patterns:
  1. Command Pattern
  2. Observer Pattern
  3. Template Method Pattern
  4. State Pattern
  5. Strategy Pattern
Multiple Patterns:
  1. Model-View-Controller Pattern
  2. Symmetric Proxy Pattern 
Please visit again for more details...

[Courtsey AS3.0 Design Patterns: William B. Sanders and Chandima Cumaranatunge]