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.

27.11 Visual reuse<br />

The aim of visual reuse is to avoid the necessity to rebuild applications from scratch. There are<br />

essentially three ty pes of visual reuse in VisualWorks, these are: cut <strong><strong>an</strong>d</strong> paste between windows, the<br />

use of subc<strong>an</strong>vases <strong><strong>an</strong>d</strong> the use of inherit<strong>an</strong>ce. Each of these will be discussed briefly below.<br />

27.11.1 Cut <strong><strong>an</strong>d</strong> paste reuse<br />

It is possible to cut <strong><strong>an</strong>d</strong> paste widgets from one window to <strong>an</strong>other using the c<strong>an</strong>vas <strong><strong>an</strong>d</strong> the copy edit<br />

menu option. Essentially you open the user interface builder on a particular window, select the elements<br />

of the window that you wish to copy, use the edit menu to copy them <strong><strong>an</strong>d</strong> then go to <strong>an</strong>other c<strong>an</strong>vas <strong><strong>an</strong>d</strong><br />

use the edit menu option paste, to place them on the new window. This copy operation also copies all<br />

the preference information defined for the first window (although it does not copy <strong>an</strong>y inst<strong>an</strong>ce variable<br />

definitions, initialization or accessor methods). All that is now required for these widgets to be available<br />

on the new window is to define them <strong><strong>an</strong>d</strong> carry out <strong>an</strong>y initialization operations required.<br />

This approach saves time on building new windows as whole window layouts (such as buttons, input<br />

fields, test labels, text boxes etc.) c<strong>an</strong> be copied at once. It is also possible to mix widgets copied from a<br />

number of different windows.<br />

However, this approach suffers with problems of mainten<strong>an</strong>ce (for both window layout <strong><strong>an</strong>d</strong> source<br />

code). For example, if the purpose of copying a set of widgets was to ensure that all windows had a<br />

similar look (for example, with the same set of buttons across the bottom of the window for operations<br />

such as next, last, quit <strong><strong>an</strong>d</strong> help). Then whenever a ch<strong>an</strong>ge was made to one window, the same ch<strong>an</strong>ge<br />

would have to be performed for every window in the system. Similarly, if the windows were on<br />

different classes it would be necessary to ensure that <strong>an</strong>y source code ch<strong>an</strong>ges were reflected in each<br />

class.<br />

M<strong>an</strong>y early graphical user interface building t ools provided only this sort of reuse. Indeed there are<br />

m<strong>an</strong>y systems still in use which provide only this level of support.<br />

27.11.2 Subc<strong>an</strong>vas reuse<br />

Each window is actually a c<strong>an</strong>vas which has certain properties including the windowSpec. These<br />

c<strong>an</strong>vases are by defaul t used to construct the window. However, the layout of part of a window c<strong>an</strong> be<br />

defined by a different specification. The top level window h<strong><strong>an</strong>d</strong>les this by treating the lower<br />

specification as a subc<strong>an</strong>vas. That is a subc<strong>an</strong>vas takes its layout from a different window specification<br />

from that of the result of the window.<br />

There are in fact two ways in which a subc<strong>an</strong>vas c<strong>an</strong> be used. These are specification based <strong><strong>an</strong>d</strong><br />

inst<strong>an</strong>ce based. We will consider each of these separately.<br />

window<br />

subc<strong>an</strong>vas<br />

window specification<br />

window<br />

subc<strong>an</strong>vas<br />

reference<br />

object providing<br />

specification <strong><strong>an</strong>d</strong><br />

functionality<br />

(a)<br />

(b)<br />

Figure 27.15: Subc<strong>an</strong>vas reuse<br />

Specification based reuse. Specification based reuse uses <strong>an</strong>other window specification (in addition<br />

to the current window specification) to define what the area of the window controlled by the subc<strong>an</strong>vas<br />

should look like. This subc<strong>an</strong>vas c<strong>an</strong> be supplied by <strong>an</strong>other application model (by referencing the other<br />

class). This is indicated in Figure 27.15(a). In this situation, the window’s application model must<br />

provide the necessary functionality required by the widgets in the subc<strong>an</strong>vas area.<br />

Inst<strong>an</strong>ce based reuse. Inst<strong>an</strong>ce based reuse differs from specification based reuse in that in addition<br />

to being able to obtain the window specification used to determine the win dow layout of the subc<strong>an</strong>vas<br />

from <strong>an</strong>other class, the functionality of the widgets is h<strong><strong>an</strong>d</strong>led by <strong>an</strong> inst<strong>an</strong>ce of that class. Thus the<br />

subc<strong>an</strong>vas now relates to a completely separate object from the remainder of the window. This is<br />

indicated in Figure 27.15(b).<br />

233

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

Saved successfully!

Ooh no, something went wrong!