Java Reference
In-Depth Information
Model View Controller
In Model View Controller (MVC) architecture, the view is the user interface. The model and
controller are the middle layer components. Let us see what MVC is all about:
User - provides inputs like entering text and pushing submit button on the user screen (view)
Controller - takes the user inputs and asks the model for information like saving values to
database as well as creating some view
Model - do work like saving to database and provide feedback to controller
View - the view constructed by the controller which a user can see on his/her screen
Now let us see how it can be implemented. For demonstration purpose let us create a website
where a student can see his/her information (name and roll number). We will just create a
small program with just a few classes. We can have one class each for controller, view and
model. To run the complete thing, we can create one additional class.
Let us elaborate some more. Let us think what methods and classes we need to create.
Model - we need information about student name and roll number. We can create a class
with get and set methods to get and set student roll number and student name.
View - we need to display information about student roll number and student name. Here
we can create a class which will display this information.
Controller - we will have a controller class which will instruct the model to get and set stu-
dent roll number and student name. Once controller gets updated from the model then it will
transmit a view based on each update from the model.
User - when the user clicks the view button then the current student information should be
displayed.
Now that we have details about classes and methods, let us make some class diagrams.
Search WWH ::




Custom Search