Structure
Figure 5.3 illustrates the static structure of the Resource Decorator pattern. The Resource interface represents any database resource, such as a connection, statement handle, or result set. A ConcreteResource class implements this interface in conjunction with a database platform or middleware product. You normally write client code in terms of the Resource interface, but interact directly with a Concrete-Resource at runtime. This enables your code to work readily with any compliant Resource implementation.

BaseResourceDecorator is an abstract class that maintains a reference to any other Resource implementation. It itself is a full Resource implementation that delegates every operation to its referenced Resource.
On its own, BaseResourceDecorator does not provide much value. Its benefits come when you extend it and add specific, additional behavior. ConcreteResourceDecorator inherits BaseResourceDecorator's automatic operation delegation and adds its own custom behavior. The end result is a full Resource implementation that you can attach to any other Resource implementation. The ConcreteResourceDecorator class only contains code related to its additional behavior, while all delegation logic happens in BaseResourceDecorator.
The client code continues to refer only to the Resource interface, but you can plug in one or more ConcreteResourceDecorators that are wrapped around the ConcreteResource of your choice.
|