Programming graphical displays is complex.
A program has to manage what
gets drawn onto the display,
it gets drawn, and when
it gets drawn.
The programmer is really only interested in
gets drawn, not
drawing is performed.
Allow the user to specify what gets drawn as an aggregation of objects and provide reusable mechanisms that control how and when those objects get drawn onto the display.
Each graphical object encapsulates an element of the display (an image, circle, rectangle, piece of text, etc.). Provide reusable code to draw the objects onto the display whenever necessary (in response to expose events or changes to the graphical objects, for example).
The programmer can then easily define the "what" of the drawing code, and reuse code that handles the "how" and "when".
It is easy to define compound graphical objects by using the CompositePattern
. Groups of multiple graphical objects are then indistinguishable from individual graphical objects. Graphical objects can be structured as a SceneGraph
if sophisticated graphical composition is required.
can be used, if the programmer needs to define new operations that can be applied to graphical objects.
The drawing algorithm can use DeferredUpdate
s, draw onto a DoubleBuffer
, and BufferGraphicCommands
to optimize display updates when multiple graphical objects are changed per update.
Known uses include HotDraw
, Visio, Microsoft Powerpoint, and a myriad of other graphical toolkits and applications.
Also see GraphicsPatterns