Tuesday, 3 May 2011

How Many Design Pattern You Know?

Each time I have been asked this question only few of the design pattern names I used to remember. Even if I go through again I not sure to remember for more than one day. So I thought to come up with simple statement which will make me to remember the name of design pattern( Atleast name :-))

I decided to create single sentence for each type of patterns.

1. Creational

Abstract Factory Creates an instance of several families of classes
Builder Separates object construction from its representation
Factory Method Creates an instance of several derived classes
Prototype A fully initialized instance to be copied or cloned
Singleton A class of which only a single instance can exist

sentence to remember
builder used prototype to build single abstract factory.

2. Structural

Adapter Match interfaces of different classes
Bridge Separates an object’s interface from its implementation
Composite A tree structure of simple and composite objects
Decorator Add responsibilities to objects dynamically
Facade A single class that represents an entire subsystem
Flyweight A fine-grained instance used for efficient sharing
Proxy An object representing another object

sentence to remember
abcd proxy is flying facade.

3. Behavioral

Chain of Responsiblity. A way of passing a request between a chain of objects
Command Encapsulate a command request as an object
Interpreter A way to include language elements in a program
Iterator Sequentially access the elements of a collection
Mediator Defines simplified communication between classes
Memento Capture and restore an object's internal state
Observer A way of notifying change to a number of classes
State Alter an object's behavior when its state changes
Strategy Encapsulates an algorithm inside a class
Template Method Defer the exact steps of an algorithm to a subclass
Visitor Defines a new operation to a class without change

sentence to remember
Interpreter commands mediator to iterate template of memento and Visitor observes state and strategy of chain.

Now I am able to remember all the design pattern names which are given above easily :-).

4 comments:

  1. Nice .. Innovative way to remember the patterns..

    Well are there any shortcuts to remember these sentences.. :)

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. My suggestion is map a good practical example for each pattern in your mind.Then the name automatically come out.Its hard to memorize these english sentences for me.:)
    Info:
    (Might be most of you people know this)
    VB.NET and C# support cross-language inheritance, allowing classes defined in one language to subclass classes defined in the other language. Developers usually compile Java to bytecode, allowing Java to run on any operating system for which a Java virtual machine is available. VB.NET and C# make use of the Strategy pattern to accomplish cross-language inheritance, whereas Java makes use of the Adapter pattern.
    (Source : Wiki).

    ReplyDelete