Object-oriented design patterns

design_pattern


Background

GoF: Gang of Four, four persons that bring the thought of patterns into software engineering.
Design patterns: elements of reusable object-oriented software: a book that marks the beginning of design patterns.
GRASP: general responsbility assignment software pattern.
Rule of Three: A good solution should be applied successfully in at least three different fields.

Rules of object orientation

Three policies:

Basic Principles: S.O.L.I.D.

Factory Method Pattern

advantages

Clinets no necessarily know the exact product names.
Which product will be created is decided by the factory itself.
No need to modify the interfaces of abstract factory and abstract products.

drawback

A new factory as well as a new product has to be added which brings more complexity.
The use of abstraction leads to difficulty of understanding.
There can be only one abstract product.

Abstract Factory Pattern

when to use

The products have more than one product groups and each time only one of them will be used.
Products from the same group are designed to be used together.

Builder Pattern

advantages

Singleton Pattern

There is only one instance of the class.
Even if more than one object of this class is created, they are all actually the same instance.

Decorator Pattern

used to expand the functions of a class or add responsibilities to the class.
when it is unrealistic to use inheritage.

Proxy Pattern

When the client does not want to directly access an object, a proxy is used to help the client to do things.

Observer Pattern

This pattern is a mechenism of dependency relationship between an object and lots of observers. When the object changes, all observers will get noticed. And there is no connection among different observers.

Strategy Pattern

define a series of algorithms and encapsulate all of them to make them replacable to each other
separate the actual algorithm from business logic

Additional Resources:
http://www.cnblogs.com/grkin/archive/2013/03/17/2964964.html