The decorator has same interfaces to component to which it enhances functions or appearance. It is also called wrapper. With this pattern, client does not need to subclass or change components it uses.
The decorator owns reference to component it decorates. The client references one component which may be a decorator or a component. The client does know who the component is because both are subclasses inherited from one common abstract class.
A facade is one kind of pattern which extracts simple interfaces from complicated classes whose details the client is not interested. Certainly the may also use those complex classes which the facade extracts simple classes from.
Singleton is a special class which has exactly one instance. It can be subclasses.
Flyweight uses sharing to support large number of fine-grained objects effectively.
Intrinsic state is stored in flyweight because it is independent of the flyweight's context, thereby making it shareable. Clients are responsible for passing extrinsic state to flyweight object.
Clients maintain a reference to flyweight object, which is created by a flyweight factory to guaranty shareable, and compute, store extrinsic state for flyweight object.
Flyweights may introduce run-time costs.
Adapter is used to realize converting the interface of one class to another interface client expects. By this, existing class can be reused to new application with incompatible interface.
There are two approaches corresponding to class and object versions of adapter pattern.
I remember that I have ever created one stack class based on c++ vector template class although it is not efficient.
Compared with decorator pattern with unchanged interface, compatible interface will be built to support new requirement.
阅读(827) | 评论(0) | 转发(0) |