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
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
can 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
The 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.