Java Reference
In-Depth Information
Model-View-Controller Pattern
The previous section demonstrated the necessity of reconciling system functionality with a
user's interaction with the application through the GUI layout. The Model-View-Controller
(MVC) pattern limits the dependencies between a system's interface and implementation, and
buffers the data and middle tiers from design decisions that may affect the presentation tier.
Why Use the MVC Pattern?
The main purpose of the MVC pattern is the separation of responsibility for the various tasks
involved in the user interface (UI). A typical UI can be split into the following areas of respon-
sibility:
1. The interface to the system
2. The displaying of the data to the end user
3. Accepting input from the user, then parsing and processing it
These three areas of responsibility correspond to the Model, the View, and the Controller,
respectively.
It is possible, using the MVC design pattern, to keep these three areas of responsibility
logically separate. On large teams it might be possible to assign these areas of responsibility to
teams who have the best skills to perform the work—for example, those who have good layout
skills might be assigned to work on the View, while those who are better at parsing inputs from
various sources might work on the Controller.
Using the MVC design pattern allows us to change the UI rapidly. For this topic's sample
assignment and for the Sun SCJD assignment we will be creating a GUI that will run as a
stand-alone application. However, by changing the View and the Controller, we can easily
create a web-based application. Another View and Controller can be used to provide a web
services interface to the application.
Tip It is often recommended that when learning any new subject you should try to put the concepts into
practice. If you are planning to study for the Sun Certified Web Component Developer certification, you could
try creating a web interface to your assignment. This can be easier than trying to implement a brand-new
project as part of your studies, as you will have already created the business logic and will therefore only be
concentrating on the information pertinent to your new certification studies.
MVC in Detail
As its name suggests, the MVC pattern consists of three primary players, as shown in Table 8-2.
The MVC pattern may seem complex, but it's actually an incredibly simple concept. The
concept is very easy to follow when it's boiled down to a real-world example. Let's consider it
from the perspective of ordering from your local fast-food restaurant.
Search WWH ::




Custom Search