Archive for September 16, 2012

How MVC belongs to only Presentation Layer?

September 16, 2012 4 comments

Spring MVC in simple terms:

It is a presentation framework, you may have doubt “How MVC belongs to only presentation layer”.

MVC Framework:

View and Controller belongs to Presentation Layer as Controller takes the URL and directs to appropriate View based on the given URL.

 MVC Flow:

  1. Request comes to the controller, controller decides is there any business logic to be implemented for this request or not.
  2.  If no business logic required it will redirect to the appropriate View. Ex: if we are requesting a login form no business logic required here so controller directly redirect login.jsp.
  3. If business logic required to the particular request it will call the appropriate Service class to process the request. Based on the service object response, controller redirects to the appropriate view.
  4. In the view if there is any data is to be shown, then the data will be taken from appropriate model.

With the above diagram View and Controller directly interacting with Presentation Layer.

And model is used by View to show the data.

So MVC belongs to Presentation Layer

MVC in Three tier architecture:

In three tier architecture we have Presentation Tier, Middle Tier, Data Access Tier, simply we can call Presentation layer, Service layer  and DAO Layer.

Presentation layer interacts with the Service layer and Service layer interacts with DAO layer.

The Flow will be like this:

  1. Request  comes to controller and controller decides whether this request needs any business logic to be implemented or not
  2. If no it simply returns a view.
  3. If yes it interacts with Service Layer and Service Layer interacts with DAO Layer
  4. Later the based on the response from Service Layer appropriate View will be shown by the Controller.

Spring recommends the same model can be used for presentation layer, In Struts we have form beans as presentation layer model. But in Spring we can use the same model across all the Three Layers.

Categories: Java, Spring