In this chapter, we are going to take a look at one of the most commonly used design patterns in J2EE Application development – the Model View Controller – MVC Pattern.
What is the Model View Controller Design Pattern?
The Model-View-Controller architecture compartmentalizes the data and business logic (model) from the presentation (view) from the user action interpreter (controller). This pattern is the hardest on the exam. The idea is closely related to the recent move from two-tier to three-tier architectures. The 3 tiers in a MVC Architecture of a J2EE Application are:
1. Model – Usually JavaBeans
2. View – Usually JSPs
3. Controller – Usually Servlets
Is
This pattern is a clear functional separation of roles. It is a formalization of the data-business-presentation movement that dominated three-tier architectures over the last decade.
Is Not
This pattern is very abstract. It is not simply a front end to a datasource connection.
Analogy
This would be like an automobile. The speed of a car is affected by the accelerator pedal (Controller), the speed is shown by the speedometer (View), and the speed is determined by the engine power (Model).
Problem
Different views of the same data are a common need. Conversely, the same client needs access to different models.
Responsibility
This pattern carefully manages communication between the client and model data and functionality. It must allow changing the client or changing the model with minimal impact on the system.
Aim
The main goal is separation of concerns. This pattern attempts to minimize the impact of changing any of the three pieces.
Primary Activity
This pattern decouples views from data and business logic; MVC interjects a controller between them, which interprets user actions into operations on the business logic and the selection of the next view to send to the user.
Context
An application is expected to support varying client and business logic tiers.
Benefits
• Various clients and data models are being developed. These two tiers need to talk to each other.
• Non-interface-specific code is duplicated in many applications.
• The same enterprise data will be accessed by different views: for example, HTML, WML, JFC/Swing, and XML.
• The same enterprise data will be accessed (requested, modified, and deleted) from various actions (HTML links, JFC/Swing events, SOAP XML calls).
Usage
Although the primary purpose of MVC is for building UIs, it can be used to establish an analogous notification protocol between non-visual objects. The Observer/Observable objects in java.util were designed with this pattern in mind.
Consequences
• Clients access a controller that accesses the model instead of the data directly.
• Another layer has to be built which adds work.
• It is easier to break a project into pieces because both the view and model developers are targeting the controller API.
Uses
Almost all J2EE applications use the MVC Pattern. Even JFC Swings technology of Java uses the MVC Pattern. Also, Struts and Velocity use this pattern as their underlying framework.
Previous Chapter: Chapter 55 - Business Delegate Pattern
Next chapter: Chapter 57 - Front Controller Pattern
Friday, April 29, 2011
Chapter 56: Model View Controller Pattern
Subscribe to:
Post Comments (Atom)
© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.
Popular Posts
-
The following are some questions that you might encounter when you face an Interview for a position of a Senior Java/J2EE Developer. Design ...
-
The following are some questions you might encounter with respect to Java Multi-threading in any Interview. Multi-threading is a powerful an...
-
The following are some questions you might encounter with respect to Java Server Pages or JSPs in any Interview. JSPs are an integral part o...
-
Access Modifiers are one of the most important topics when it comes to taking the SCJP exam. You can expect a number of questions from these...
-
Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the a...
-
1. Does Hibernate implement its functionality using a minimal number of database queries to ensure optimal output? Hibernate can make cert...
-
The last thing we need to look at in our series of chapters on threads, is how threads can interact with one another to communicate about, a...
-
You might be wondering, is Stack and Heap such a large topic that I have dedicated one full chapter to it? Actually it isnt such a big topic...
-
In the chapter on Inner classes, I had promised that we will look in more detail about the different types of inner classes. Well here we ar...
-
This chapter is probably going to be the most important or rather most confusing chapter from the exam perspective. You can expect atleast a...

Good post. I have written a simple web application example using MVC pattern. You can find it here http://manikandanmv.wordpress.com/2010/12/07/struts-example/
ReplyDeleteps: This example will be useful for readers after reading your design pattern explanation.
Hi
ReplyDeleteI read this post 2 times. It is very useful.
Pls try to keep posting.
Let me show other source that may be good for community.
Source: financial controller interview questions
Best regards
Jonathan.