First page Back Continue Last page Overview Graphics
IOstreams and the Decorator Pattern (The solution)
In order to allow various extensions or “decorations” that could be applied to various types of Input/Output streams, the IO package contains a set of classes which implement the decorator design pattern.
Example: Reader Decorators - Use a “decorator”: a class that is both derived from Reader, and encloses another Reader object as a data member (received by constructor of new class).
All Reader methods are “forwarded” (or delegated) to the inner Reader object.
New attributes (methods) use the inner Reader object as well.