O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Classic Example of Decorator: Streams

The Java class libraries provide a classic example of the DECORATOR pattern in the overall design of Java input and output streams. A stream is a serial collection of bytes or characters, such as those that appear in a document. In Java, each stream object usually contains another stream object to which it forwards its operations. This structure is typical of DECORATOR.

The DECORATOR pattern arranges for each decorator object to contain another decorator object. In this regard, a decorator is like a slim composite whose elements each have a single child. Unlike the COMPOSITE pattern, whose purpose is to compose aggregate objects, the purpose of DECORATOR is to compose behavior.

Structurally, DECORATOR

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required