Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
• reusability of application <strong><strong>an</strong>d</strong> / or user interface components,<br />
• ability to develop the application <strong><strong>an</strong>d</strong> user interface separately,<br />
• ability to inherit from different parts of the class hierarchy.<br />
In fact, in the MVC, the user interface is further subdivided into the output (to the screen) part <strong><strong>an</strong>d</strong><br />
the input (from the user) part. This enables different output elements (look) to be connected with<br />
different input elements (feel). Each part of the MVC therefore attempts to provide the functionality<br />
required by one of these three areas.<br />
26.2.1 The structure of the MVC<br />
The MVC is actually made up of three cooperating components. T hese three components are known as<br />
the Model, the View <strong><strong>an</strong>d</strong> the Controller. These three components are illustrated in Figure 26.2 <strong><strong>an</strong>d</strong> are<br />
collectively known as the MVC triad.<br />
Model View Controller<br />
Data Display Menu<br />
Cut<br />
Paste<br />
Copy<br />
Save<br />
Figure 26.2: The use of the MVC<br />
This division of responsibility in the MVC is broken down in the following way:<br />
• Model - The information model which h<strong><strong>an</strong>d</strong>les data storage <strong><strong>an</strong>d</strong> informatio n processing. That is,<br />
it m<strong>an</strong>ages the behaviour of the data in the application domain.<br />
• View - Which h<strong><strong>an</strong>d</strong>les the visual display (the output part). That is, it h<strong><strong>an</strong>d</strong>les how the<br />
information about the application is displayed on the screen.<br />
• Controller - This provides the user interaction to, or control of, the information models<br />
processing (the input part). That is, it h<strong><strong>an</strong>d</strong>les the mouse <strong><strong>an</strong>d</strong> keyboard inputs.<br />
The diagram in Figure 26.2 illustrates the idea behind each aspect of the MVC. To use the MVC<br />
architecture you must underst<strong><strong>an</strong>d</strong> the division of labor within the MVC triad. However, you should be<br />
aware that in real applications, this division of labor is not always as cle<strong>an</strong> as it should be. Fo r example,<br />
controller like behaviour c<strong>an</strong> leak into the view object, while view like behaviour c<strong>an</strong> leak into the<br />
controller object!<br />
In addition, you must also underst<strong><strong>an</strong>d</strong> how the three elements communicate (even if you are using<br />
one of the window building to ols). Of course in <strong>an</strong>y application there are m<strong>an</strong>y objects which aren’t<br />
models (or which are contained within the model but don’t realize that they are part of a model or a<br />
graphical system). However, they invariably work with the model to provide the overall application.<br />
26.2.2 The elements in the MVC triad<br />
26.2.2.1 Models<br />
As has already been stated a model h<strong><strong>an</strong>d</strong>les data storage <strong><strong>an</strong>d</strong> information processing. That is, it h<strong><strong>an</strong>d</strong>les<br />
how the application data is processed (i.e. the functionality of the system). That me<strong>an</strong>s that model s are<br />
responsible for holding data, operating on that data <strong><strong>an</strong>d</strong> responding to requests for information.<br />
Essentially, they are exactly what you have already been looking at throughout this book: “they are one<br />
or more objects which provide some set of operati ons”. For example, the Statement class in the<br />
fin<strong>an</strong>cial m<strong>an</strong>ager application, which you have encountered a number of times in this book, could be<br />
considered to be a model. It held information on deposits <strong><strong>an</strong>d</strong> withdrawals. It responded to new deposits<br />
214