GOF patterns for GUI Design

James Noble

MRI, Scho ol of MPCE,

Macquarie University, Sydney.

[email protected]

June 1, 1997

Abstract

The book intro duced twenty-three patterns for ob ject oriented software design.

These patterns are used widely, but only in their intended domain of software design. We describ e

how six of these patterns can b e used for the conceptual design of graphical user interfaces. By

using these patterns, designers can pro duce interfaces which are more consistent, make go o d use of

screen space, and are easier to use.

Intro duction

This pap er presents six patterns for graphical user interface GUI  design Prototyp e, Singleton, Adap-

1

tor, Comp osite, Proxy, and Strategy, each inspired by the GOF pattern of the same name. These

patterns have b een used widely in GUIs b eginning with the early work on the Star [10] and Smalltalk

[9], and wehave illustrated these patterns with examples from more recent GUIs.

To apply these patterns to GUI design, wehave translated the GOF patterns from the domain of

OO software design to that of GUI design. Although b oth the GOF patterns and our GUI patterns

are expressed in terms of ob jects, interfaces, messages, and so on, we have interpreted these terms

into the GUI domain. We use object to mean an individually manipulable GUI comp onent, suchasan

icon, a dialog b ox, or a window. A single ob ject may app ear in more than one way | for example,

a do cument ob ject may app ear as an icon when it is closed, and a window when it is op en. Ob jects

have attributes, such as editable text b oxes, radio buttons, and check buttons, and behaviour, which can

be invoked by buttons, menus, keystrokes, or by directly manipulating the ob ject. A group of ob jects

with similar attributes and b ehaviour forms a class, for example, all window ob jects could b elong to the

window class. Classes can b e group ed using inheritance to capture ner distinctions b etween ob jects,

for example, all directory windows could b elong to one class, all application windows to another, b oth

of which could inherit from the window class.

This translation highlights an imp ortant di erence b etween the GOF domain and the GUI domain:

GOF patterns can address the implementation of ob jects, while GUI patterns necessarily address only

the interfaces of GUI ob jects [7]. For those patterns that are mainly concerned with interfaces, suchas

Proxy or Prototyp e, this makes little di erence. For patterns where the main concern is encapsulation,

such as Strategy, the corresp onding GUI pattern brings out a secondary asp ect of the pattern, suchas

factoring or lo cating ob jects.

These patterns do not directly address usability, although wehave found these patterns in interfaces

whichhave b een extensively designed for usability. We b elieve these patterns are orthogonal to other

techniques for user interface design such as walkthroughs, prototyp e, metrics, or visualisation, just

as patterns for software development are mostly orthogonal to other software development techniques.

1

A GOF Pattern is a pattern from the Design Patterns b o ok [8], written by the so-called Gang of Four | Gamma, Helm, Johnson, Vlissides.

Similarly, in the same way that the GOF patterns address the middle ground between programming

languages and metho dologies, these patterns also seem to t b etween detailed user interface guidelines [1,

11] which are the sp eci cations of user interface languages and overarching user interface metho dologies

[6].

Form and Content

The bulk of this pap er presents six of the GUI patterns wehave identi ed. These patterns are organised

in the same way and presented in the same order as the corresp onding patterns the GOF b o ok. We b egin

with the creational patterns Prototyp e and Singleton, then present the structural patterns Adaptor,

Comp osite, and Proxy, and conclude with the Strategy b ehavioural pattern. This pap er contains a

pattern catalogue, rather than a system or language of patterns.

For space reasons, wehave used a compressed form to present the patterns. Each pattern has a name

and a statementofintent, derived from the corresp onding sections of the GOF pattern. A short problem

statement addresses the motivation and applicability of the pattern, and then the forces the pattern

resolves are itemised explicitly. Asp ects of the solution's structure, participants, collab orations, and

implementation are then combined in a single section. A picture illustrates an example of the pattern

in use, taking the place of GOF's sample co de. Finally, the p ositive + or negative consequences

of the pattern are outlined and examples of known uses are reviewed. Essentially, this form compresses

the ma jor narrative sections of the GOF form into two short paragraphs problem and solution, each

with an asso ciated bullet list forces and consequences, resp ectively.

Most of the forces are derived from the pattern's context, and are isomorphic to the forces in the

related GOF pattern. This isomorphism is imp ortant, since it ensures the shap e of the solution is similar

across the domains. The patterns also refer to three forces which are sp eci c to the GUI design domain:

 Interface consistency is an explicit force in GUI design. In an OO design, consistency resolves

other forces, such as reusability.

 Screen real estate is an imp ortant and often scarce resource.

 Ob ject identity in GUIs means that an ob ject should only app ear in one lo cation on the screen.

That is, GUIs don't have p ointers.

Related Patterns

Given that the rst software pattern language was ab out user interface design [3], it is quite surprising

that so few patterns and pattern languages have b een written for this domain. The to ols and materials

metaphor has b een describ ed in a pattern language, although the language concerns implementation as

much as design [16]. Pattern languages have also b een written for designing essay based web sites [14]

and form style windows [4].

Envoi

We b elieve that many GOF patterns capture deep general prop erties of ob ject oriented software design.

This pap er is an exp eriment to determine whether and howwell the patterns app ear in the related,

but signi cantly di erent, domain of GUI design.

GUI Prototyp e Ob ject Creational

Intent Sp ecify the kinds of ob jects to create using a prototypical instance, and create new

ob jects by copying this prototyp e.

Problem GUIs supp ort many di erent kinds of ob jects whichhave di erent capabilities. Users

need to be able to create the right kind of ob ject to hold their data. For example,

desktops supp ort a number of di erent do cument typ es, such as pro cessed words,

spreadsheets, and databases. How can the user create new objects?

Forces The GUI Prototyp e pattern resolves the following forces:

 The user needs to create various classes of do cuments.

 You cannot anticipate all the classes in the system.

 Ob jects should b e created in a consistentway.

Solution Make a prototype ob ject for each class. Let the user create new ob jects by copying

the appropriate prototyp e. Each class should understand a \copy" message, inherited

from the class of all user ob jects.

Example In the Self UI all ob jects are created by duplicating existing prototyp es | there is no

\create" op eration. Macintosh System 7 allows do cuments to b e marked as \stationery

pads" | when the user op ens stationery pad, the pad is copied and the copy is op ened.

Consequences The GUI Prototyp e pattern has the following b ene ts and liabilities:

+ Users can create ob jects of all copyable classes in the same way.

+ New classes can b e added by supplying new prototyp es.

+ Users can make their own classes, by copying ob jects they've initialised.

Users may need to empty old data out of newly copied ob jects.

Users may forget to copy ob jects and accidently edit the prototyp e directly.

Known Uses Prototyp es were rst used in Sketchpad [19]. They are used explicitly in the Self UI

[18], the MoDE Comp oser [17] and the Macintosh [2]. Wehave suggested many users

use prototyp es instinctively [13].

GUI Singleton Ob ject Creational

Intent Ensure a class only has one instance, and provide a global p oint of access to it.

Problem Some classes should always have exactly one instance. For example, ob jects represent-

ing real hardware resources, like disks, printers, or networks, or sp ecial system ob jects

like trash cans, should only app ear once in any GUI. How should you manage these

unique objects?

Forces The GUI resolves the following forces:

 There should b e only one instance of these ob jects.

 The single instance should b e widely available.

 The user interface should b e consistent.

 Screen real estate is limited.

Solution Make a singleton ob ject, and design the singleton's class so that the user can't copy

or delete the singleton. Create the singleton when the GUI starts, and place it on the

screen typically on the desktop so it is always available.

Example The Recycle Bin in Windows95 is a singleton | it do es not include the deletion and

renaming commands provided by most ob jects.

Consequences The GUI Singleton pattern has the following b ene ts and liabilities:

+ Only one instance of a singleton can b e created.

+ The singleton is readily available on the desktop.

+ The singleton b ehaves mostly like other ob jects.

The GUI is less consistent, b ecause singletons can't b e copied or deleted,

A singleton is always present, o ccupying screen real estate.

Known Uses The Macintosh and Windows95 GUIs use this pattern for several desktop icons. The

VisualWorks Launcher [15] is a variant of singleton, since although it is created on

startup, it can b e deleted.

See Also GUI Proxy can allow a Singleton ob ject to app ear to b e in more than one place.

GUI Adaptor Ob ject Structural

Intent Convert the interface of a class into another interface users exp ect. Adaptor lets classes

work together that couldn't otherwise b ecause of incompatible interfaces.

Problem Interfaces are worlds unto themselves, each with their own culture, language, and style.

Users often need to inhabit several worlds, for example, when using legacy mainframe

applications from GUI desktops, or using one desktop from another. How can the user

access one interfacefrom another incompatible interface?

Forces The GUI Adaptor pattern resolves the following forces:

 The user needs to use ob jects whichhave incompatible interfaces.

 You don't want to mo dify either interface.

 The user interface should b e consistent.

Solution Make an adaptor ob ject which hosts one interface inside the other. An adaptor is a

normal ob ject in the host interface, graphically containing the hosted interface. Let

the user interact with the hosted interface via the adaptor. Adaptors often provide

out-of-band op erations for manipulating the connection b etween the twointerfaces.

Example The Windows NT interface can b e adapted to run inside the X Window system the

Tektronix menu bar manipulates the adaptor. Windows NT can host textual appli-

cations via terminal emulators.

Consequences The GUI Adaptor pattern has the following b ene ts and liabilities:

+ The hosted interface can b e used from the host interface.

+ Neither interface needs to b e mo di ed.

+ A generic adaptor can adapt sets of interfaces, such all ASCI I text applications.

The resulting user interface may b e inconsistent if the host interface's conventions

are not used within the adaptor.

Known Uses Most GUIs include terminal emulators which give access to textual applications. Win-

dows and Macintosh interfaces can b e adapted to run under X, and vice versa. Web

browsers adapt the WWW user interface to wide range of host interfaces.

See Also A Legacy Wrapp er is a more general form of this pattern [12].

GUI Comp osite Ob ject Structural

Intent Comp ose ob jects into tree structures to represent part-whole hierarchies. Comp osite

lets clients treat individual ob jects and comp ositions of ob jects uniformly.

Problem Many GUI ob jects are made up recursively of other GUI ob jects. For example, disks

contain directories, and directories contain other directories and les. How can the

user manipulate composite objects?

Forces The GUI Comp osite pattern resolves the following forces:

 The user needs to manipulate the whole comp osite ob ject.

 The user needs to manipulate the individual parts of the comp osite.

 The user interface should b e consistent.

Solution Make comp osite ob jects which can recursively contain other ob jects, b oth comp osites

and primitives. Make a common class for all the op erations shared by primitive and

comp osite ob jects. Particular ob jects should inherit from this class, and extend it to

provide op erations applicable to them.

Example In the Self UI, any graphical ob jects can b e combined emb edded to build up com-

p osite structures. Windows NT represents directory structures as comp osite ob jects.

Consequences The GUI Comp osite pattern has the following b ene ts and liabilities:

+ The user can manipulate b oth the whole ob ject and the individual parts.

+ The interface for common op erations is consistent.

It can b e hard to isolate a particular individual part inside the whole.

Known Uses The Macintosh and Windows95 interfaces use comp osite ob jects to represent directory

structures. MacDraw and many other drawing editors let the user construct comp osite

pictures by explicitly grouping and ungrouping graphical ob jects.

GUI Proxy Ob ject Structural

Intent Provide a surrogate or placeholder for another ob ject to provide access to it.

Problem Some ob jects are never where the user wants them to b e. For example, the user might

want to store a le deep within a directory hierarchy, but keep it easily accessible. Or

the user would liketodownload a web page, ignoring any in-line images but keeping

the do cument's structure intact. How can an object be in two places at once?

Forces The GUI resolves the following forces:

 The user wants an ob ject in two places at once.

 GUI ob ject identity requires that an ob ject can only b e in one place.

 You don't want to mo dify or move the original ob ject.

 The original ob ject may b e exp ensive or dicult to retrieve.

 The user interface should b e consistent.

Solution Make a proxy ob ject to stand in for remote or exp ensive ob jects. Put the proxy where

you'd like to put the original ob ject, but can't. Let the proxy b ehaveasifitwere the

original ob ject, but visually distinguish the proxy from the original.

Example Windows95 shortcuts act as proxies so that an ob ject can app ear in multiple places on

the desktop. Netscap e uses icons as proxies for images whichhaven't b een downloaded.

Consequences The GUI Proxy pattern has the following b ene ts and liabilities:

+ The original ob ject app ears to b e in two places at once.

+ The original ob ject do esn't need to b e changed.

+ Access to the original ob ject via the proxy is transparent.

+ The user can distinguish b etween the original ob ject and the proxy.

If the original ob ject b ecomes unavailable, the proxy will b e unusable.

Known Uses Macintosh aliases and Windows95 shortcuts act as remote proxies for ob jects in other

places. Netscap e uses icons as virtual proxies for images which haven't b een down-

loaded. Manyweb pages use small image thumbnails as proxies for larger images.

See Also Pattern-Oriented SoftwareArchitecture also describ es the Proxy pattern [5].

GUI Strategy Ob ject Behavioural

Intent De ne a family of algorithms, and make them interchangeable.

Problem An ob ject uses several algorithms, each with its own interface and customisable param-

eters. The user needs to set the parameters for the algorithm they havechosen. For

example, a screen saver may provide a number of di erent display algorithms text,

2D graphics, 3D graphics each with its own parameters the text to display, or the

colours, textures, and 3D ob jects to draw. How can the user deal with the di erent

algorithms?

Forces The GUI Strategy pattern resolves the following forces:

 An ob ject needs di erent algorithms which require di erent parameters.

 Users should cho ose the algorithm and its parameters.

 The user interface should b e consistent.

 Screen real estate is limited.

Solution Make a separate strategy ob ject to represent each algorithm, and make the algorithm's

parameters into the attributes of the strategy ob ject. Make the strategy ob ject b elong

to the ob ject which uses the algorithms. The user can cho ose an algorithm via the

main ob ject, then interact with the strategy ob ject to set the algorithm's parameters.

Example Windows NT uses strategy ob jects to set the parameters for its screen saver.

Consequences The GUI Strategy pattern has the following b ene ts and liabilities:

+ The strategy ob jects explicitly represent the di erent algorithms.

+ The user can select an algorithm and set its parameters.

+ Presenting one strategy ob ject at a time preserves real estate.

Changing strategy ob jects may make the interface less consistent.

The interface includes an increased numb er of ob jects.

Known Uses Windows NT uses strategy ob jects to set parameters for its printer drivers, as well as

its screen saver. Paint Shop Pro and XV use strategy ob jects to con gure their le

conversion algorithms.

Acknowledgements

Thanks are due to , the EuroPLOP'97 shepherd for this pap er, to Michael Richmond,

Jonathon Tidswell, Geo Outhred, and Larry Constantine for comments on drafts of this pap er, and

for help with Macs and PCs.

References

[1] Apple Computer, Inc. Human Interface Guidelines: The Apple Desktop Interface. Addison-Wesley, 1987.

[2] Apple Computer, Inc. Inside Macintosh,volume VI. Addison-Wesley, 1991.

[3] Kent Beck and . Using pattern languages for ob ject-oriented programs. Technical rep ort,

Tektronix, Inc., 1987. Presented at the OOPSLA-87 Workshop on Sp eci cation and Design for Ob ject-

Oriented Programming.

[4] Mark Bradac and Becky Fletcher. Developing form style windows. In Pattern Languages of Program Design,

volume 3. Addison-Wesley, 1997.

[5] Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal. Pattern-Oriented

SoftwareArchitecture. John Wiley & Sons, 1996.

[6] Dave Collins. Designing Object Oriented User Interfaces. Benjamin/Cummings, 1995.

[7] Larry L. Constantine. Getting the message. Object Magazine, Septemb er 1996.

[8] Erich Gamma, Richard Helm, Ralph E. Johnson, and John Vlissides. Design Patterns. Addison-Wesley,

1994.

[9] Adele Goldb erg. Smal ltalk-80: The Interactive Programming Environment. Addison-Wesley, 1983.

[10] J. Johnson, T. L. Rob erts, W. Verplank, D. C. Smith, C. Irby, M. Beard, and K. Mackey. The Xerox Star:

A retrosp ective. IEEE Computer, 229, 1989.

[11] Microsoft Inc. The Windows Interface Guidelines for Software Design. Microsoft Press, 1995.

[12] Diane E. Mularz. Pattern-based integration architectures. In Pattern Languages of Program Design.

Addison-Wesley, 1994.

[13] James Noble. Prototyp e based user interfaces. Technical rep ort, MRI, Scho ol of MPCE, Macquarie Uni-

versity, Sydney, 1996. Presented at the COTAR'96 Workshop, Melb ourne, 1996.

[14] Rob ert Orenstein. A pattern language for an essay-based web site. In Pattern Languages of Program Design,

volume 2. Addison-Wesley, 1996.

[15] ParcPlace Systems. VisualWorks Smal ltalk User's Guide, 2.0 edition, 1994.

[16] Dirk Riehle and Heinz Kulligho  ven. A pattern language for to ol construction and integration based on the

to ols and materials metaphor. In Pattern Languages of Program Design. Addison-Wesley, 1994.

[17] Yen-Ping Shan. MoDE: A UIMS for Smalltalk. In OOPSLA Proceedings, Octob er 1990.

[18] Randall B. Smith, John Maloney, and David Ungar. The Self-4.0 user interface: Manifesting a system-wide

vision of concreteness, uniformity, and exibility. In OOPSLA Proceedings, 1995.

[19] Ivan E. Sutherland. Sketchpad: A man-machine graphical communication system. In Proceedings AFIPS

Spring Joint Computer Conference,volume 23, pages 329{346, Detroit, Michigan, May 1963.