Intent
Separate the mechanics of drawing from the act of drawing.
Motivation
In building an OO graphics system you must connect to an existing host windowing system. The host windowing system API usually contains operations for drawing graphics primitives (lines, rectangles, arcs, etc.) in a window. Mapping these API calls to a set of objects often relies upon a basic conception of the way people draw.
Structure
(* Diagram to be supplied later -- send to ward*)
Participants
Pen will often directly wrapper the API calls necessary to implement the drawing primitives. Most windowing systems require a window handle to send these calls, so it obtains that from Paper. Paper is often subclassed to represent the different types of graphics mediums (bitmaps, screens and printers). Person will be subclassed to represent each specific type of visual object.
Known Uses
Smalltalk/V and VisualWorks utilize this pattern in their graphics systems. In Smalltalk/V, Pen is represented by the class Pen, Paper is represented by the class GraphicsMedium? and its subclasses. The Person is represented by subclasses of SubPane?. In VisualWorks Pen is the class GraphicsContext?. Paper is the class DisplaySurface? and its subclasses. The Person is represented by the VisualComponent hierarchy. IBM Smalltalk has a similar concept, but it does not map quite as well as Smalltalk/V and VisualWorks.
Related Patterns
The Paper, Pen and Person pattern can be combined with Decorator and Composite to form a graphics hierarchy of visuals that can contain other visuals.