Implementation of MVC pattern for single and multiple objects

The name of the pictureThe name of the pictureThe name of the pictureClash 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();









share|improve this question

























    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();









    share|improve this question





















      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();









      share|improve this question











      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();











      share|improve this question










      share|improve this question




      share|improve this question









      asked Apr 28 at 9:34









      colastar

      111




      111

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation