Implementation of MVC pattern for single and multiple objects
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I've implemented a student administration with MVC pattern (Tutorial: Link). I've decided to divid the students in "SingleStudentModel" and "MultipleStudentModel", but I'm not sure if that make sense in my case. In general, I'm not satisfied with my solution. Is it possible to handle single student and multiple students with one controller?
Is it ok if a model import into a view class (see StudentsView.java)?
How can I improve this project?
Thanks in advance.
Student.java (Model, data class (?))
public class Student
private String name;
private int nr;
public Student(String _name, int _nr)
this.name = _name;
this.nr = _nr;
// get set
SingleStudentModel.java (Model)
public class SingleStudentModel
private Student student;
// get set
StudentController.java (Controller -> SingleStudentModel)
public class StudentController
private SingleStudentModel model;
private StudentView view;
public StudentController(SingleStudentModel _model, StudentView _view)
this.model = _model;
this.view = _view;
// set get
public void updateView()
view.printStudentDetails(model.getStudent().getName(), model.getStudent().getNr());
MultipleStudentModel.java (Model)
public class MultipleStudentModel
private Collection<Student> students = new ArrayList<Student>();
public Collection<Student> getStudents()
return students;
public void setStudents(Student student)
this.students.add(student);
StudentsController.java (Controller -> StudentsModel)
public class StudentsController
private MultipleStudentModel model;
private StudentsView view;
public StudentsController(MultipleStudentModel _model, StudentsView _view)
this.model = _model;
this.view = _view;
public void updateView()
view.printStudentList(model.getStudents());
StudentView.java
public class StudentView
public void printStudentDetails(String _name, int _nr)
System.out.println("Student: ");
System.out.println("name: " + _name);
System.out.println("nr: " + _nr);
StudentsView.java
import com.mvc.model.Student;
import java.util.Collection;
public class StudentsView
public void printStudentList(Collection<Student> students)
System.out.println("nStudent list");
for(Student item : students)
System.out.println("name: " + item.getName());
System.out.println("nr: " + item.getNr());
Main.java
public class Main
public static void main(String args)
//Single student
SingleStudentModel model = new SingleStudentModel();
StudentView view = new StudentView();
StudentController controller = new StudentController(model, view);
model.setStudent(new Student("John", 1));
controller.updateView();
//Multiple student
MultipleStudentModel model2 = new MultipleStudentModel();
StudentsView view2 = new StudentsView();
StudentsController controller2 = new StudentsController(model2, view2);
model2.setStudents(new Student("Zelda", 2));
model2.setStudents(new Student("Link", 3));
controller2.updateView();
java mvc
add a comment |Â
up vote
2
down vote
favorite
I've implemented a student administration with MVC pattern (Tutorial: Link). I've decided to divid the students in "SingleStudentModel" and "MultipleStudentModel", but I'm not sure if that make sense in my case. In general, I'm not satisfied with my solution. Is it possible to handle single student and multiple students with one controller?
Is it ok if a model import into a view class (see StudentsView.java)?
How can I improve this project?
Thanks in advance.
Student.java (Model, data class (?))
public class Student
private String name;
private int nr;
public Student(String _name, int _nr)
this.name = _name;
this.nr = _nr;
// get set
SingleStudentModel.java (Model)
public class SingleStudentModel
private Student student;
// get set
StudentController.java (Controller -> SingleStudentModel)
public class StudentController
private SingleStudentModel model;
private StudentView view;
public StudentController(SingleStudentModel _model, StudentView _view)
this.model = _model;
this.view = _view;
// set get
public void updateView()
view.printStudentDetails(model.getStudent().getName(), model.getStudent().getNr());
MultipleStudentModel.java (Model)
public class MultipleStudentModel
private Collection<Student> students = new ArrayList<Student>();
public Collection<Student> getStudents()
return students;
public void setStudents(Student student)
this.students.add(student);
StudentsController.java (Controller -> StudentsModel)
public class StudentsController
private MultipleStudentModel model;
private StudentsView view;
public StudentsController(MultipleStudentModel _model, StudentsView _view)
this.model = _model;
this.view = _view;
public void updateView()
view.printStudentList(model.getStudents());
StudentView.java
public class StudentView
public void printStudentDetails(String _name, int _nr)
System.out.println("Student: ");
System.out.println("name: " + _name);
System.out.println("nr: " + _nr);
StudentsView.java
import com.mvc.model.Student;
import java.util.Collection;
public class StudentsView
public void printStudentList(Collection<Student> students)
System.out.println("nStudent list");
for(Student item : students)
System.out.println("name: " + item.getName());
System.out.println("nr: " + item.getNr());
Main.java
public class Main
public static void main(String args)
//Single student
SingleStudentModel model = new SingleStudentModel();
StudentView view = new StudentView();
StudentController controller = new StudentController(model, view);
model.setStudent(new Student("John", 1));
controller.updateView();
//Multiple student
MultipleStudentModel model2 = new MultipleStudentModel();
StudentsView view2 = new StudentsView();
StudentsController controller2 = new StudentsController(model2, view2);
model2.setStudents(new Student("Zelda", 2));
model2.setStudents(new Student("Link", 3));
controller2.updateView();
java mvc
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I've implemented a student administration with MVC pattern (Tutorial: Link). I've decided to divid the students in "SingleStudentModel" and "MultipleStudentModel", but I'm not sure if that make sense in my case. In general, I'm not satisfied with my solution. Is it possible to handle single student and multiple students with one controller?
Is it ok if a model import into a view class (see StudentsView.java)?
How can I improve this project?
Thanks in advance.
Student.java (Model, data class (?))
public class Student
private String name;
private int nr;
public Student(String _name, int _nr)
this.name = _name;
this.nr = _nr;
// get set
SingleStudentModel.java (Model)
public class SingleStudentModel
private Student student;
// get set
StudentController.java (Controller -> SingleStudentModel)
public class StudentController
private SingleStudentModel model;
private StudentView view;
public StudentController(SingleStudentModel _model, StudentView _view)
this.model = _model;
this.view = _view;
// set get
public void updateView()
view.printStudentDetails(model.getStudent().getName(), model.getStudent().getNr());
MultipleStudentModel.java (Model)
public class MultipleStudentModel
private Collection<Student> students = new ArrayList<Student>();
public Collection<Student> getStudents()
return students;
public void setStudents(Student student)
this.students.add(student);
StudentsController.java (Controller -> StudentsModel)
public class StudentsController
private MultipleStudentModel model;
private StudentsView view;
public StudentsController(MultipleStudentModel _model, StudentsView _view)
this.model = _model;
this.view = _view;
public void updateView()
view.printStudentList(model.getStudents());
StudentView.java
public class StudentView
public void printStudentDetails(String _name, int _nr)
System.out.println("Student: ");
System.out.println("name: " + _name);
System.out.println("nr: " + _nr);
StudentsView.java
import com.mvc.model.Student;
import java.util.Collection;
public class StudentsView
public void printStudentList(Collection<Student> students)
System.out.println("nStudent list");
for(Student item : students)
System.out.println("name: " + item.getName());
System.out.println("nr: " + item.getNr());
Main.java
public class Main
public static void main(String args)
//Single student
SingleStudentModel model = new SingleStudentModel();
StudentView view = new StudentView();
StudentController controller = new StudentController(model, view);
model.setStudent(new Student("John", 1));
controller.updateView();
//Multiple student
MultipleStudentModel model2 = new MultipleStudentModel();
StudentsView view2 = new StudentsView();
StudentsController controller2 = new StudentsController(model2, view2);
model2.setStudents(new Student("Zelda", 2));
model2.setStudents(new Student("Link", 3));
controller2.updateView();
java mvc
I've implemented a student administration with MVC pattern (Tutorial: Link). I've decided to divid the students in "SingleStudentModel" and "MultipleStudentModel", but I'm not sure if that make sense in my case. In general, I'm not satisfied with my solution. Is it possible to handle single student and multiple students with one controller?
Is it ok if a model import into a view class (see StudentsView.java)?
How can I improve this project?
Thanks in advance.
Student.java (Model, data class (?))
public class Student
private String name;
private int nr;
public Student(String _name, int _nr)
this.name = _name;
this.nr = _nr;
// get set
SingleStudentModel.java (Model)
public class SingleStudentModel
private Student student;
// get set
StudentController.java (Controller -> SingleStudentModel)
public class StudentController
private SingleStudentModel model;
private StudentView view;
public StudentController(SingleStudentModel _model, StudentView _view)
this.model = _model;
this.view = _view;
// set get
public void updateView()
view.printStudentDetails(model.getStudent().getName(), model.getStudent().getNr());
MultipleStudentModel.java (Model)
public class MultipleStudentModel
private Collection<Student> students = new ArrayList<Student>();
public Collection<Student> getStudents()
return students;
public void setStudents(Student student)
this.students.add(student);
StudentsController.java (Controller -> StudentsModel)
public class StudentsController
private MultipleStudentModel model;
private StudentsView view;
public StudentsController(MultipleStudentModel _model, StudentsView _view)
this.model = _model;
this.view = _view;
public void updateView()
view.printStudentList(model.getStudents());
StudentView.java
public class StudentView
public void printStudentDetails(String _name, int _nr)
System.out.println("Student: ");
System.out.println("name: " + _name);
System.out.println("nr: " + _nr);
StudentsView.java
import com.mvc.model.Student;
import java.util.Collection;
public class StudentsView
public void printStudentList(Collection<Student> students)
System.out.println("nStudent list");
for(Student item : students)
System.out.println("name: " + item.getName());
System.out.println("nr: " + item.getNr());
Main.java
public class Main
public static void main(String args)
//Single student
SingleStudentModel model = new SingleStudentModel();
StudentView view = new StudentView();
StudentController controller = new StudentController(model, view);
model.setStudent(new Student("John", 1));
controller.updateView();
//Multiple student
MultipleStudentModel model2 = new MultipleStudentModel();
StudentsView view2 = new StudentsView();
StudentsController controller2 = new StudentsController(model2, view2);
model2.setStudents(new Student("Zelda", 2));
model2.setStudents(new Student("Link", 3));
controller2.updateView();
java mvc
asked Apr 28 at 9:34
colastar
111
111
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193136%2fimplementation-of-mvc-pattern-for-single-and-multiple-objects%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password