01.01.2015 Views

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

292<br />

Sunday Afternoon<br />

Controller: The code that reacts to user requests, modifies the data, and controls<br />

the flow of the application<br />

This basic structure is shown in Figure 28-3. MVC may be applied to almost any application<br />

you develop, whether it is Web based or not. For a non-Web application, your application may<br />

have a set of classes for your data model that coordinate database access and data manipulation,<br />

another set of classes for your GUI views, and a third set of classes for your controlling<br />

event-handling code. One of the most important advantages of MVC is that it allows you to<br />

more easily change one aspect of the system without affecting the other aspects, exemplifying<br />

loose coupling. For example, you may want to offer different interfaces for the traditional<br />

wired Web devices and the wireless devices without changing or duplicating the data model. If<br />

you have intermixed your database access with your GUI code, then changing the GUI without<br />

changing the data model will be much more difficult. Because the programmer who is good at<br />

writing data model code is likely not the same programmer who is good at writing GUI view<br />

code, another advantage of MVC is that it simplifies the independent development of these<br />

components.<br />

Model<br />

Controller<br />

Data<br />

Classes<br />

Business<br />

Services<br />

Application<br />

Flow Control /<br />

Event Handlers<br />

View<br />

GUI<br />

Classes<br />

Figure 28-3 <strong>UML</strong> Component diagram, Model View Controller<br />

In Web development, the view is the Web content such as HTML. The model is the business<br />

logic for data manipulation and database access and is usually written in a programming<br />

language like Java. The controller is the code for verifying the data coming in from<br />

the HTTP request, interacting with the data model, and selecting the next view (Web page)<br />

to be sent to the user. Just as in non-Web application development, separating these three<br />

aspects will greatly simplify your maintenance and improve both cohesion and coupling. In<br />

the remaining portion of this session, you separate the model from the view. In Session 29,<br />

you separate out the controller.<br />

JavaBeans<br />

The JSP in Session 27 contained an unusually small amount of Java code because it had<br />

extremely little dynamic content, but most JSPs will have to use a lot more Java code for<br />

querying and updating databases, calculating data, and other operations. The result is that<br />

you have a lot of Java code inside your Web content. With this usage, a JSP is really just a

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

Saved successfully!

Ooh no, something went wrong!