29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

a particular problem, the user gains a better underst<strong><strong>an</strong>d</strong>ing of the framework as a whole. It is essentially<br />

a tutorial on using a framework, but one which is more th<strong>an</strong> a cookbook.<br />

The problem with cookbooks is that they describe a single way in which the framework will be used.<br />

A good framework will be used in ways that its designers never conceived. Thus a cookbook is<br />

insufficient on its own to describe every use of the framework. Of course a develope r’s first use of a<br />

framework usually fits the stereotypes in the cookbook. However, once they go beyond the examples in<br />

the cookbook, they need to underst<strong><strong>an</strong>d</strong> the details of the framework. The problem is that cookbooks tend<br />

not to describe the framework its elf. But in order to underst<strong><strong>an</strong>d</strong> a framework, you need to have<br />

knowledge of both its design <strong><strong>an</strong>d</strong> its use. Patterns provide opportunities for describing both the design<br />

<strong><strong>an</strong>d</strong> the use of the framework as well as including examples, all within a coherent whole. I n some ways<br />

patterns act like a hyper -graph with links between parts of patterns. To illustrate the ideas behind<br />

frameworks <strong><strong>an</strong>d</strong> patterns the next section will present the framework HotDraw <strong><strong>an</strong>d</strong> a tutorial HotDraw<br />

pattern example explaining how to construct a simple drawing tool.<br />

Heading<br />

Name<br />

Intent<br />

Also known as<br />

Motivation<br />

Applicability<br />

Structure<br />

Particip<strong>an</strong>ts<br />

Collaborations<br />

Consequences<br />

Implementation<br />

Sample Code<br />

Known uses<br />

Related patterns<br />

Table 21.1: The design pattern template<br />

Usage<br />

The name of the pattern<br />

This is a short statement indicating the purpose of the pattern. It includes<br />

information on its rationale, intent, problem it addresses etc.<br />

Any other names by which the pattern is known.<br />

Illustrates how the pattern c<strong>an</strong> be used to solve a particular problem.<br />

This describes the situation in which the pattern is applicable. It may also<br />

say when the pattern is not applicable.<br />

This is a (graphical) description of the classes in the pattern.<br />

The classes <strong><strong>an</strong>d</strong> objects involved in the design <strong><strong>an</strong>d</strong> their responsibilities.<br />

This describes how the classes <strong><strong>an</strong>d</strong> objects work together.<br />

How does the pattern achieve its objective? What are the trade offs <strong><strong>an</strong>d</strong><br />

results of using the pattern? What aspect of the system structure does it let<br />

you vary independently.<br />

What issues are there in implementing the design pattern.<br />

Code illustrating how a pattern might be implemented.<br />

How the pattern has been used in the past. Each pattern has at least two<br />

such examples.<br />

Closely related design patterns are listed here.<br />

21.3 An introduction to HotDraw<br />

What is HotDraw? HotDraw is a drawing framework developed by Ralph Johnson at the University of<br />

Illinois at Urb<strong>an</strong>a-Chapaign [Johnson 1992]. It is a reusable design for a drawing tool expressed as a set<br />

of classes. However, it is more th<strong>an</strong> just a set of classes; it possesses the whole structure of a drawing<br />

tool, which only needs to be parameterized to create a new drawing tool. It c<strong>an</strong> therefore be viewed as a<br />

basic drawing t ool <strong><strong>an</strong>d</strong> a set of examples which c<strong>an</strong> be used to help you develop your own drawing<br />

editor!<br />

Essentially HotDraw is a skeleton DrawingEditor waiting for you to fill out the specific details. That<br />

is, all the elements of a drawing editor are provided including a basic working editor., which you, as a<br />

developer, customize as required. What this me<strong>an</strong>s to you is that you get a working system much, much<br />

sooner <strong><strong>an</strong>d</strong> with a great deal less effort.<br />

21.3.1 The HotDraw framework<br />

HotDraw was first presented at the OOPSLA’92 conf erence in a paper entitled “Documenting<br />

Frameworks using Patterns” by Ralph Johnson [Johnson 1992] . This paper is somewhat abstract,<br />

however the appendices included with the paper are very useful as guides for ch<strong>an</strong>ging the default<br />

drawing editor. The conc ept behind frameworks is that a set of abstract classes are only so useful, it is<br />

much more useful to capture the design in the classes along with concrete examples. The combination<br />

of design information, concrete examples <strong><strong>an</strong>d</strong> <strong>an</strong> explicit skeleton to work with is easier to underst<strong><strong>an</strong>d</strong>.<br />

Indeed it is usually the case that concrete examples to follow <strong><strong>an</strong>d</strong> modify are a much better way to learn<br />

174

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!