Java Reference
In-Depth Information
ALTERNATIVE TO MVC—MEET MVP
Sorry for the disillusion, but MVP does not stand for most valuable pattern. MVP
is the abbreviation for model view presenter, which is an alternative to model view
controller. Instead of creating a triangular relationship between controller, view,
and model like MVC, MVP offers one way of communication to each party—the
presenter takes charge of all communication between the view and model. It is
pretty popular in .NET, Silverlight, Google Web Toolkit, and Vaadin.
The principle difference between Type I and Type II is where the controller logic is located: in Type I
it is in the view, and in Type II it is in a servlet.
Many frameworks, such as Spring MVC, Struts, Grails, and Wicket, implement their own version
of the Type II MVC pattern. For example, Spring MVC includes the concept of the Dispatcher
servlet that interacts with the HTTP requests and delegates to the controller, view (and view
resolver), and handlers. Figure 14-2 shows a diagram of Spring's implementation of the MVC
pattern.
Handler
Mapping
Controller
View Resolver
View
Dispatcher Servlet
HTTP Request
HTTP Response
FIGURE 14-2: Diagram of Spring's MVC implementation
IMPLEMENTING THE MVC PATTERN IN PLAIN CODE
You are going to implement the MVC pattern with the help of the action pattern. This pattern takes
on the responsibility of determining where to redirect the user based on the user's request. It helps
maintain the single responsibility of the controller.
 
Search WWH ::




Custom Search