Skip to content
Snippets Groups Projects
Commit 2b2685f8 authored by W. Spencer Smith's avatar W. Spencer Smith
Browse files

Restoring old tutorial, as a potential resource with additional information on MVC

parent 5600100c
No related branches found
No related tags found
No related merge requests found
File added
File added
public class MVCPatternDemo {
private static Student retriveStudentFromDatabase(){
Student student = new Student();
student.setName("Robert");
student.setStudentNumber(10);
return student;
}
public static void main(String[] args) {
//fetch student record based on his Student Number from the database
Student model = retriveStudentFromDatabase();
//Create a view : to write student details on console
StudentView view = new StudentView();
StudentController controller = new StudentController(model, view);
controller.updateView();
//update model data
controller.setStudentName("John");
controller.setStudentNumber(11);
controller.updateView();
}
}
public class Student {
private String name;
private int number;
public int getStudentNumber() {
return number;
}
public void setStudentNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class StudentController {
private Student model;
private StudentView view;
public StudentController(Student model, StudentView view){
this.model = model;
this.view = view;
}
public void setStudentName(String name){
model.setName(name);
}
public String getStudentName(){
return model.getName();
}
public void setStudentNumber(int number){
model.setStudentNumber(number);
}
public int getStudentstudentNumber(){
return model.getStudentNumber();
}
public void updateView(){
view.printStudentDetails(model.getName(), model.getStudentNumber());
}
}
public class StudentView {
public void printStudentDetails(String studentName, int studentNumber){
System.out.println("---Student---");
System.out.println("Name: " + studentName);
System.out.println("Student Number: " + studentNumber);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment