A Wrapper class
"wraps" an object of another class. It is used to implement a
design pattern that has an instance of an object and presents its own
interface or behavior to that object, without changing the original
class (this is the key point!). These patterns demonstrate delegation.
There are a number of design patterns that can be considered Wrappers:
Adapter -
An Adapter translates the interface of one class to match another. It
allows an object that implements a set of features to be used with
software that expects a different interface, without changing the code
for the original class. The Adapter class has an instance of the the
class being adapted (the Adaptee). It implements its own set of methods
that then call the methods in the Adaptee. It is often used to wrap a legacy class (i.e. old)
that is targeted for future replacement.
Proxy -
the Proxy pattern controls access to an object (the Real Object). The
Proxy implements the same interface as the Real Object, but may add
additional behavior, such as security checks, before calling the methods
in the the Real Object.
Decorator
- a Decorator augments the behavior of an existing class. It has the
same super class as the decorated class (and sometimes extends the
decorated class). When the method is called with the decorator, it then
calls the methods in the decorated class and further processes the
results. It is both "isa" Decorated class and "hasa" Decorated class.
Java has these wrapper-classes as decorators: Synchronization Wrappers. Note: do NOT use these in your Project code; you must code the multithreading yourself.