Sep 082011
 

Go around and look for some method to remember Design Pattern, I saw a site summarize each Design Pattern with a line like this:

  • Abstract Factory: Creates an instance of several families of classes
  • Prototype: A fully initialized instance to be copied or cloned
  • Singleton: A class in which only a single instance can exist

But how can you remember it all? I cannot imagine that I can recall “Abstract Factory” is “Creates an instance of several families of classes” at all.

Design Pattern is so abstract and so hard to remember, so each time I write an entry about Design Pattern I do my best to put an easy to remember example. I believe the real life examples will be easier to understand and remember than the descriptions and principles.

Now let’s me summarize some Design Patterns by using Images of real life example.

 Singleton Pattern
searchdaily net java singleton design pattern thumb Remember Design Patterns by Images singleton pattern example images thumb Remember Design Patterns by Images

 

It’s the pattern of single service but multiple user like: there’s one receptionist at a hotel and there are multiple visitors. There is one President in a country and million citizens to manage

 Abstract Factory Pattern

Just think of the abstract Vehicle Factory that ferrari vs audi r8 thumb Remember Design Patterns by Imagescan produce any cars. And there are real Vehicle Factory like one is based in Germany (Audi and Mercedes) or factory is based in Italy like Ferrari and Iveco.

The same type of  products are created by different factories give different result in the end.

Factory Method Pattern

image thumb7 Remember Design Patterns by ImagesThe Factory method is much like Abstract Factory: to create different objects. But the difference is that Factory Method is not based on the different Factories but to base on different Parameters passed to the creator.

Take the calculator for example, base on the type of calculator we select, the different calculators will be created

 

Chain of Responsibility Pattern

The Chain of Responsibility pattern avoids coupling the sender of a request to the receiver, by giving more than one object a chance to handle the request. Mechanical coin sorting banks use the Chain of Responsibility. Rather than having a separate slot for each coin denomination coupled with receptacle for the denomination, a single slot is used. When the coin is dropped, the coin is routed to the appropriate receptacle by the mechanical mechanisms within the bank.

chain of responsibility pattern thumb Remember Design Patterns by Images


Builder Pattern

The Builder pattern separates the construction of a complex object from its representation, so that the same construction process can create different representation. This pattern is used by fast food restaurants to construct children’s meals. Children’s meals typically consist of a main item, a side item, a drink, and a toy (e.g., a hamburger, fries, coke, and toy car). Note that there can be variation in the contents of the children’s meal, but the construction process is the same. Whether a customer orders a hamburger, cheeseburger, or chicken, the process is the same. The employee at the counter directs the crew to assemble a main item, side item, and toy. These items are then placed in a bag. The drink is placed in a cup and remains outside of the bag. This same process is used at competing restaurants.

builder pattern example thumb Remember Design Patterns by Images

Prototype Pattern

To remember this pattern you should think of Robot Cloning or Toyjava prototype clone thumb Remember Design Patterns by Images Cloning using Doraemon Magic Cloning Mirror.

This is the method of creating object by allowing them to create duplicates of themselves.

Adapter Pattern

The easiest way to remember this pattern is to remember the Universal Adapter.

adapter design pattern universal power adapter thumb Remember Design Patterns by Images

You create the adapter to transform resource so that other adapter can get from it. That all you should know about Adapter Pattern.

Composite Pattern

The good example for Composite Pattern should be the robot Voltron which is created by combining five Lion robots.

voltron composite design pattern thumb Remember Design Patterns by Images

“The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object” is the only description you should remember

Façade Pattern

It’s the way of wrapping and hiding the complicated details from the client. Instead it gives the client a simpler interface to do the job.

And the best example of this should be what Sun has applied this pattern into EJB Session Façade.

facade design pattern session facade thumb Remember Design Patterns by Images

Decorate Pattern

The best Pattern for adding more features to an existing class without changing it should be the Decorate Pattern which utilize both extending and wrapping of classes.

The good example of this pattern is to extend and add rich features to a simple Text Editor like Notepad.

decorator pattern example thumb Remember Design Patterns by Images

Proxy Pattern

For you guys study RMI in college may hear of Stub and Skeleton before realize the Proxy Pattern.

bank atm proxy Remember Design Patterns by Images

The good example to remember is about the Bank and the ATM. Where the ATM is actually is representative of the Bank but most of the work will be dispatched to the only bank to process.

Observer Pattern

Observer Pattern maybe heard later than Event and Listener by some people. The best example for Observer Pattern is the Publish Subscribe cycle.

observer pattern thumb Remember Design Patterns by Images 

In Observer Pattern, you don’t need to wait endlessly for some event.observer pattern 2 thumb Remember Design Patterns by Images Instead when some event happens you will get notification.

Another real life example of Observer Pattern is the mailman. You don’t need to go to the office all the time, all the day to ask for new mail. Instead whenever there’s a new email for you. The mailman will come to your house and knock on your door.

The same thing for your mobile phone to notify you about sms message or new incoming call.

(to be continued…)

  2 Responses to “Remember Design Patterns by Images”

  1. This is really fantastic. using simple real world items like mailman, robots,notepad to explain the concept is great. would like to read more. thanks for sharing :)

  2. I love this. You are doing such a great job showing real world example. THANK YOU>

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>