Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
about a set of classes, th<strong>an</strong> to attempt to underst<strong><strong>an</strong>d</strong> the class <strong><strong>an</strong>d</strong> work from there (particularly when<br />
you are learning <strong>Smalltalk</strong>). For example, if a method takes a block as <strong>an</strong> argument, what is that block<br />
supposed to look like? An example or two are often invaluable.<br />
Every HotDraw application is comprised of a number of elements, these are the Drawing Editor, the<br />
Drawing V iew, the Drawing Controller, the Drawing, figures in the drawing, h<strong><strong>an</strong>d</strong>les, constraints<br />
between drawings <strong><strong>an</strong>d</strong> creation tools. Each of these is explained briefly below:<br />
DrawingEditor DrawingEditor is a subclass of Model that represents a graphical drawing ed itor.<br />
It is the model of the MVC triad that includes a<br />
DrawingView <strong><strong>an</strong>d</strong> a<br />
DrawingController. It shares the DrawingView <strong><strong>an</strong>d</strong> the DrawingController with a<br />
Drawing.<br />
DrawingView A DrawingView is the view component of a MVC triad. The Drawing <strong><strong>an</strong>d</strong> the<br />
DrawingController are the other components. A DrawingEditor also uses the<br />
DrawingView in a MVC triad.<br />
DrawingController A DrawingController is the controller component of a pair of MVC triads.<br />
A Drawing <strong><strong>an</strong>d</strong> A DrawingView is one pair <strong><strong>an</strong>d</strong> a DrawingEditor <strong><strong>an</strong>d</strong> DrawingView<br />
are the other pair. A DrawingController’s primary task is to delegate mouse <strong><strong>an</strong>d</strong> keyboard<br />
activity to the current tool of the Drawing.<br />
Drawing A drawing is a directed graph of figures (or complex figures). As indicated above it is a model<br />
in a MVC triad with the DrawingView <strong><strong>an</strong>d</strong> DrawingController.<br />
Figures A Figure is a kind of drawing element or widget which describes how it should be drawn<br />
within a DrawingEditor. A CompositeFigure is a figure which c<strong>an</strong> contain other<br />
figures as components, which all have <strong>an</strong> influence on what the composite figure looks like.<br />
CompositeFigure also defines a bounding box which is independent of its sub -components.<br />
Only components which are wholly within the bounding box are actually displayed. Unlike<br />
VisualComponents in VisualWorks, figures keep track of which objects which depend on them.<br />
H<strong><strong>an</strong>d</strong>les All figures c<strong>an</strong> potentially have h<strong><strong>an</strong>d</strong>les. H<strong><strong>an</strong>d</strong>les are a way to modify a figure’s attributes, for<br />
example by resizing the figure, or by linking a figure to <strong>an</strong>other figure <strong><strong>an</strong>d</strong> thereby crea ting a<br />
dependency. The Figure class defines a method h<strong><strong>an</strong>d</strong>les which returns a basic set of h<strong><strong>an</strong>d</strong>les for<br />
resizing a figure. It is therefore common for subclasses of figure to redefine the h<strong><strong>an</strong>d</strong>les method,<br />
either to overwrite this, or to add to it (in which cas e the method would “call super” h<strong><strong>an</strong>d</strong>les at<br />
some point).<br />
Constraints HotDraw provides Constraint objects which are used to express dependencies between<br />
objects. A MultiheadedConstraint, which is a subclass of constraint, makes the state of<br />
one object be the function of the states of m<strong>an</strong>y other objects. The one object is the “sink” <strong><strong>an</strong>d</strong><br />
the m<strong>an</strong>y objects are the “sources”. For example, if the value of one cell in a spreadsheet is the<br />
sum of five other cells, then the five cells are the sources <strong><strong>an</strong>d</strong> the cell with the sum is the sink.<br />
CreationTools These are used to create a new inst<strong>an</strong>ce of a figure. They are parameterized by the class<br />
of the figure to display, the icon to display in the tool palette <strong><strong>an</strong>d</strong> the cursor to use while that tool<br />
is selected.<br />
21.3.2 Obtaining HotDraw<br />
HotDraw is available by <strong>an</strong>onymous FTP from the <strong>Smalltalk</strong> repository at st.cs.uiuc. There are versions<br />
available for most of the recent releases of ParcPlace <strong>Smalltalk</strong> (e.g. VisualWorks version 1.0, 2.0 <strong><strong>an</strong>d</strong><br />
2.5). You should follow t he installation instructions <strong><strong>an</strong>d</strong> then immediately save the image onto your<br />
local file store <strong><strong>an</strong>d</strong> exit VisualWorks.<br />
21.3.3 Examples with HotDraw<br />
The examples provided with HotDraw include a Pert Chart tool, a HyperCard clone, HotPaint <strong><strong>an</strong>d</strong><br />
Network Editor which allows you to play with nodes in a network which are either attracted or repulsed<br />
by each other <strong><strong>an</strong>d</strong> a diagramming inspector. If you have access to HotDraw (e.g. via ftp) then explore<br />
them! Explore the patterns at the end of this chapter which describes the patt erns based on one of these<br />
example applications.<br />
175