MVC in JSP and Servlet

MVC in JSP and Servlet

A story

A guy who wants to own a own restaurant. He does not have any employee, so he decides to take all the roles in the restaurant him self.

What are the steps that owner have to do in order to serve the food to customer?
1. Get the customer's order.
2. Prepare food in the kitchen.
3. Place and consolidate food on the tray as per the order.
4. Get the tray to the customer and serve.
It's like coding everything in a single servlet!.
Instead of him doing all the works him self, he hires somebody who experts in cook.
Now, what are the steps those guys do in order to serve food to customer?
1. Get the customer's order.
2. Pass on the required info to the chef who prepares the food.
3. Consolidate/decorate the food.
4. Get the tray to customer and serve.
It's like using business service beans!.
Now, he want to improve the process yet again and brings in another recruit into the restaurant. This person who specializes in decorating the food.
Now, what are the steps those guys do in order to serve food to customer?
1. Get the customer's order.
2. Pass on the required info to the chef who prepares the food.
3. Pass the cooked food to the food decorator who decorates the food
4. Get the tray to customer and serve.
It's like using business service beans and JSP. That sounds like MVC!.

MVC

Model

It is actually business service. It could also be class calling business service. It concerns with getting the data, providing data and being the data it self. Both data of the application as well as the behavior will be called as Model

View

It renders the model into a form that actually displayable, presentable to the user. This is UI part of it.

Controller

It passes the necessary data to model, let's say do it works and then it calls the right view in order to do the presentation

Why MVC

1. Controller is separated from model.
2. View is separated from model.
3. View is separated from controller.
There is separation of concerns and there is minimal change to the other rolls if any one of the rolls happens to be changed.
We have client talking to controller, controller talks to the model and view is for the rendering output. So that it consumable by client.

0 comments:

Post a Comment

Search This Blog

Powered by Blogger.