Introduction to OOP Chapter 24: Design Patterns : next previous audio real text

Decorator (Filter, Wrapper)

Problem: Allow functionally to be layered around an abstraction, but still dynamically changable.

Solution: Combine inheritance and composition. By making an object that both subclasses from another class and holds an instance of the class, can add new behavior while referring all other behavior to the original class.

Example Input Streams in the Java I/O System

	// a buffered input stream is-an input stream
class BufferedInputStream extends InputStream {

	public BufferedInputStream (InputStream s) { data = s; }
	...

		// and a buffered input stream has-an input stream
	private InputStream data;
}
An instance of BufferedInputStream can wrap around any other type of InputStream, and simply adds a little bit new functionality.
Intro OOP, Chapter 24, Slide 13