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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong><strong>an</strong>d</strong> wit hdrawals <strong><strong>an</strong>d</strong> requests for the current bal<strong>an</strong>ce. It could therefore be used with a view <strong><strong>an</strong>d</strong> a<br />

controller as part of a graphic application.<br />

In some versions of <strong>Smalltalk</strong> (for example VisualWorks) there is <strong>an</strong> explicit class Model from<br />

which models c<strong>an</strong> inherit model like behaviour. Figure 26.3 illustrates part of the Model class hierarchy.<br />

It illustrates that classes such as Browser <strong><strong>an</strong>d</strong> Inspector are actually models, which hold some<br />

data. However, there is no re ason why <strong>an</strong> object which will be used as part of the MVC triad must be a<br />

subclass of Model.<br />

The import<strong>an</strong>t point to note about <strong>an</strong> object, which will be used as a model within the MVC, is that<br />

it must provide the application functionality independent of the type of user interface being used (ignore<br />

the issue of printing the statement in the fin<strong>an</strong>cial m<strong>an</strong>ager example here). In earlier chapters, we<br />

explicitly sent messages to the fin<strong>an</strong>cial m<strong>an</strong>ager application via the Workspace. However, these<br />

messages could have been sent by <strong>an</strong>other object, such as a b<strong>an</strong>king system object, or by a controller or<br />

view object.<br />

Figure 26.3: Part of the Model class hierarchy<br />

26.2.2.2 Views<br />

The information held by the model is present ed to a user via a view. That is, a view obtains information<br />

from the model <strong><strong>an</strong>d</strong> decides how to present that information to the user. This c<strong>an</strong> be in the form of text,<br />

graphics, widgets, or combinations of these etc. However, <strong>an</strong> import<strong>an</strong>t point to note is th at the view<br />

should not possess <strong>an</strong>y knowledge of what the data me<strong>an</strong>s, neither should it ch<strong>an</strong>ge it, initiate some<br />

application process because of it, or process it (other th<strong>an</strong> what is necessary for the user interface).<br />

Notice that it is the view that decides how the data should be displayed independently of the model.<br />

The result of this is that we could have one view which displays the bal<strong>an</strong>ce after each tr<strong>an</strong>saction as<br />

a table, <strong><strong>an</strong>d</strong> <strong>an</strong>other as a graph. Depending on which view we connect to the model, we will ge t a<br />

different user interface. However, we will not have had to ch<strong>an</strong>ge the model at all.<br />

Figure 26.4 illustrates part of the View class hierarchy. This hierarchy illustrates how the various<br />

elements typicall y found in a graphical interface are different types of view. For example, a<br />

RadioButtonView is a subclass of LabelledButtonView, which in turn is a subclass of<br />

BasicButtonView, which is a subclass of SimpleView, which is a direct subclass of View.<br />

Similarly ScrollBar, MenuItemView <strong><strong>an</strong>d</strong> LauncherView are all direct subclasses of View.<br />

This figure also illustrates one of the interesting facilities in VisualWorks. Consider the<br />

215

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

Saved successfully!

Ooh no, something went wrong!