After this brief introduction the book explains many design patters in a unified fashion. Each subsequent chapter consists of a description of a pattern, one or many real life examples, and discussion of its benefits and drawbacks. The following patterns are described:
- Singleton - this pattern is used when only one instance of object is necessary, for example in case of page-specific code. Another example is branching to support incompatible browsers. A real life example is creating XHR object.
- Factory is used to implement various kinds of managers. Imagine a complex object that consists of a number of other objects. This pattern is useful if the type of each component is known only at run-time, it makes it easy to replace the parts.
- Bridge - decouples abstraction from its implementation so that they may vary independently.
- Composite - implements a tree-like data structure.
- Facade. This is a convenience method. One usage example is a class that accounts for differences among various browsers.
- Adapter - wrap an existing interface into a new one.
- Decorator - it is possible to use it as class decorator to extend exisitng functionality as well as function decorator, for example to implement a profiler.
- Flyweight allows one to optimize the memory consumption of a class. The idea is to separate the class into intrinsic and extrinsic states. An example is implementation of a tooltip.
- Proxy - two types of proxies exist: remote proxy facilitates access to a remote object, whereas virtual proxy allows to delay the instantiation of a complex object. This gives an impression of big speedup.
- Observer - publish/subscribe architecture. Example implementation: animation.
- Command implements an action which is separated from the object that invokes it. It is possible to use the action with a button or with a menu item.
- Chain of responsibility тАУ allows to implement requests that are passed down a chain of hierachical objects.