HOME | J2ME | Struts | AJAX | SOAP | SOA MEDIA STREAMING AXIS |
Struts for Begginers
Introduction
MVC Design Pattern
Installation
Action Servlets
Hello World
Forms & ActionForms
Messages Resources
Data Bases
Exceptions
Acess ActionForms from JSP
Logic Tag

 

 

Struts for Beginners: Model View Controller (MVC) Design Pattern

Back | Tutorial Home | Next

Every program has a User Interface, event handling, business logic and data access. If these components are mixed together what we get is a spaghetti code. This kind of code though functional is difficult to maintain and small changes to a part of code will have a spiral effect to other sections of the program.

To get around this problem Model View Controller approach was developed by small talk developers and was widely embraced by the developer community. Various Java technologies like Swing, J2EE, Struts draw a lot of features from MVC design pattern.

In MVC the programs are divided into three parts – Model, View and Controller. This way there is segregation of various layers and the changes can be done to individual layers without effect or minimal effect to the other layers. Lets us look into these layers in more detail

View

View manages the display to the end user. View should not contain any business logic.This layer does following tasks

  • Show hypertext, images, forms to the user
  • Retrieve processed data from the model and display to the user along with hypertext, images and forms.
  • Client side validations
  • Server side validations

If you are web programmer these are your JSP files.

Model

Model is back bone of any program. This modal consists of data in a particular state and actions that can modify this state. These actions are usually called business logic. In simpler words this layer does all the data related work given below

  • Beans with get and set methods
  • Business logic
  • Data Access from any data source database, flat file, web service, Entity Bean, LDAP server etc.

If you are web programmer these are your BO’s (Buisness Objects), DAO’s (Data Access Objects) , VO’s(Value Objects) etc.

Controller

Controller is the layer between View and Model. This layer does following tasks

  • When ever a View sends the request, the Controller finds appropriate Model component and forwards the request to this component.
  • Receives the response from the model and routes the data to appropriate View component.

If you web programmer these are your Servlet files.

As you go through next few sections you will understand how this design pattern is implemented in Struts.

Back | Tutorial Home | Next

site comments powered by Disqus
Download our free toolbar

toolbar powered by Conduit

| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back |