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.

names) <strong><strong>an</strong>d</strong> the actions for buttons (the messages to send if they are selected). We c<strong>an</strong> now get the<br />

system to define these for us aut omatically. This is done using the ‘Define’ option from the c<strong>an</strong>vas tool.<br />

This brings up the definer window as illustrated in Figure 27.9. This allows the user to select which<br />

aspects <strong><strong>an</strong>d</strong> which actions they wish to define. This c<strong>an</strong> be used to ensure that modifications made to the<br />

definitions by the developer do not get over written.<br />

Figure 27.9: The Definer<br />

Different things happen to inpu t fields (<strong><strong>an</strong>d</strong> to lists <strong><strong>an</strong>d</strong> tables) th<strong>an</strong> to action buttons. In the case of<br />

<strong>an</strong> input field the system defines <strong>an</strong> inst<strong>an</strong>ce variable on the class <strong><strong>an</strong>d</strong> creates <strong>an</strong> accessor method as<br />

illustrated in Figure 27.10. This accessor method also provides a lazy initialization approach to the<br />

inst<strong>an</strong>ce variable.<br />

For <strong>an</strong> action the definer merely creates a stub method which returns self. This ensure that when the<br />

window is created <strong>an</strong> exception is not generated when a button is pressed. Th e user is then able to<br />

redefine the action methods to perform the desired operations.<br />

Figure 27.10: The defined entry aspect<br />

27.7 Initialization<br />

It is import<strong>an</strong>t when using <strong>an</strong> a pplication model to ensure that <strong>an</strong>y initialization performed does not<br />

overwrite that accomplished higher up in the ApplicationModel class hierarchy. For example, in<br />

Figure 27.11 we define <strong>an</strong> initialization method for th e simple to do list Org<strong>an</strong>izer presented in Figure<br />

27.12. The first thing that this method does is to send a message initialize up the class hierarchy<br />

using:<br />

super initialize.<br />

This ensures that the initialization steps performed by the ApplicationModel will be carried out<br />

first. This is essential because if initialize merely overwrote the inherited method, then the user<br />

229

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

Saved successfully!

Ooh no, something went wrong!