Java Reference
In-Depth Information
In our controller class, we have called both view and model classes. The class variables
defined in the model class get assigned values through the get and set methods and values
are coming from the user input.
Finally we need to run our demo by calling our controller class. For this we will create a
MVCdemo class.
public class MVCDemo {
public static void main(String[] args) {
//fetch student record based on his roll no from the database
Model model = retrieveStudentFromDatabase();
//Create a view : to write student details on console
View view = new View();
Controller controller = new Controller(model, view);
controller.updateView();
//update model data
controller.setStudentName("Amanda");
controller.updateView();
}
private static Model retrieveStudentFromDatabase(){
Student student = new Student();
student.setName("Sean");
student.setRollNo("21");
return student;
}
}
Search WWH ::




Custom Search