Our very first pattern revisited... MVC

As luck would have it, the very same pattern we’ve been using in the book is on the exam. The last two patterns we’re covering are presentation tier patterns, as was the Intercepting Filter. First we’ll pick up where we left off talking about MVC. That discussion will lead us into Struts and finally Front Controller.

Where we left off...

Let’s do a quick review of where we left off in Chapter 2.

MODEL

Holds the real business logic and the state. In other words, it knows the rules for getting and updating state.

A Shopping Cart’s contents (and the rules for what to do with it) would be part of the Model in MVC.

It’s the only part of the application that talks to the database.

CONTROLLER

Takes user input from the request and figures out what it means to the model.

Tells the model to update itself, makes the model state available for the view (the JSP) and forwards to the JSP.

image with no caption

VIEW

Responsible for the presentation. It gets the state of the model from the Controller (although not directly; the Controller puts the model data in a place where the View can find it).

Note

Off Track: GUI MVC vs Web MVC

MVC existed before the World Wide Web came along. In its first incarnation, MVC was a design to simplify complex GUI applications. First created in Smalltalk, one of MVC’s chief attributes was that the View would be notified automatically of changes to the Model.

More ...

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.