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.
How the update message is h<strong><strong>an</strong>d</strong>led is the responsibility of the receiver (in this case the view). For<br />
example, in order to find out what ch<strong>an</strong>ge has occurred, the view will need to request some information<br />
maintained within the model. Thus the information model only needs to send the ch<strong>an</strong>ge method to<br />
itself at the appropriate times, the views must then h<strong><strong>an</strong>d</strong>le the update: message i ndependent of the<br />
model.<br />
depedents<br />
model<br />
model<br />
view<br />
controller<br />
view<br />
controller<br />
model<br />
Figure 26.6: The dependency relationship within the MVC<br />
In Figure 26.6 notice that the view <strong><strong>an</strong>d</strong> the controller both have direct links to the model <strong><strong>an</strong>d</strong> to each<br />
other. This me<strong>an</strong>s that the controller c<strong>an</strong> send requests for services directly to the model while the view<br />
c<strong>an</strong> request state information directly from the model. Also note that the controller <strong><strong>an</strong>d</strong> view both<br />
possess explicit links to each other which allows them to communicate directly. However, although the<br />
model must know that something may be interested in it (i.e. it must send itself one of the ch<strong>an</strong>ged<br />
messages), it does not know what that thing is - it could be <strong>an</strong>y t ype of object including a view. Also<br />
remember that it is the view that would have had to make itself a dependent of the model <strong><strong>an</strong>d</strong> thus the<br />
model developer need never know how the model would be used.<br />
This arr<strong>an</strong>gement me<strong>an</strong>s that:<br />
• Views <strong><strong>an</strong>d</strong> controllers tend to be tightly coupled.<br />
• Views <strong><strong>an</strong>d</strong> controllers come in pairs. To support this most views in VisualWorks know what<br />
controller they should have <strong><strong>an</strong>d</strong> c<strong>an</strong> inst<strong>an</strong>tiate it for you.<br />
• More th<strong>an</strong> one view c<strong>an</strong> be associated with a single model.<br />
This last situation is k nown as having multiple views <strong><strong>an</strong>d</strong> is illustrated in Figure 26.7. Thus the same<br />
information c<strong>an</strong> be displayed simult<strong>an</strong>eously by different views. All of which are updated as<br />
appropriate, if <strong><strong>an</strong>d</strong> when required.<br />
dependents<br />
model<br />
view1<br />
controller<br />
model<br />
viewN<br />
controller<br />
model<br />
view<br />
controller1<br />
model<br />
view<br />
controllerN<br />
model<br />
Figure 26.7: Multiple views<br />
26.3 The MVC with the statement model<br />
Using the fin<strong>an</strong>cial m<strong>an</strong>ager application example described earlier in this book, we will look at how the<br />
bal<strong>an</strong>ce might be displayed <strong><strong>an</strong>d</strong> u pdated. The diagram illustrated in Figure 26.8 shows the three<br />
elements of the MVC triad, the model (in this case <strong>an</strong> inst<strong>an</strong>ce of statement - hence the use of statement<br />
in brackets to indicate we me<strong>an</strong> a statement <strong><strong>an</strong>d</strong> not a general type of model object), the view <strong><strong>an</strong>d</strong> the<br />
controller.<br />
218