0

I'm developing a software project in java swing. I want to follow MVC design pattern for better maintainability, portability and reliability. I've looked upon MVC in Swing on internet and found some good results like THIS , THIS , THIS, THIS, THIS and few more (youtube too) and studied them. Then I built a design architecture for my project based on MVC design pattern. Here is the structure which simulate my actual requirements:

image

Here is little description about the architecture

  • Main Controller: It is responsible to initialize and to start the application. It initialize MainView and some other sub-controller like StudentController,TeacherController. It Contains some methods like getStudentView(), getTeacherView() which provide viewable components of Student TAB, Teacher TAB to MainView
  • Main View: It is the main view which is JFrame that contains JTabbedPane which uses MainController#getXXXView() to display view in its tabs. (Here XXX can be replaced by Student, Teacher or any other viewable component which is provided by Main Controller
  • Student Controller: It controls the StudentView and Student model and Student model interface. It initialize the Student View and provides this view to Main Controller which is further provide view to Main View
  • Student View: It is a JPanel which contains JTable to display the student information and some JButton like add Student, Edit, delete etc.
  • Student: It is Student model class that has name, rollNo etc fields to store student information.
  • Student Model Interface: It is service layer. It takes a Student argument and send/add it to Student Viewable Model and store into database using Student Database Model.
  • Student Viewable data Model: It is a TableModel that is used to define JTable in Student View
  • Student Database Model: Contains method to store/retrieve student information in/from database
  • Teacher Controller: Just like Student Controller except it controls the teacher related tasks.
  • Other Controller: Represents many Student Controller like controllers

NOTE Teacher Controller and other controllers have same hierarchy as that of Student Controller. These controllers access their models and view. For e.g. Teacher Controller have Teacher View, Teacher and Teacher Model Interface

Working of the project

  • Firstly Main Controller initialize the Main View and all the sub-controllers and start the application.

  • Student Controller implements ActionListener and act when there is an event in Student View. It is responsible to add, edit, delete student information. It takes information from Student View, wrap in Student object and pass it to Model Interface

  • Model interface then pass Student Object to Student Database Model which store/update/delete the data in database. If it is successful, then Model Interface update Student Viewable data model which is a Table Model that reflects changes in Student View

So my question is whether it is a good design for this kind of application and if it is not, then what should do I do. How can I refine the design for better maintainability, reliability portability. What are some recommendations

I think its a straight and rigid question but I can't do better.

11
  • First, Swing is already a MVC (albeit a MV-C), trying to wrap another "pure" MVC on the top is going to make your life, complicated. When you're looking at you design, ask your self the simple question - how easy would it be to remove any one part and replace it with something else? If you find the answer to be anything other then easy, then your design is wrong Commented Nov 6, 2017 at 20:49
  • 2
    Why is the Student separated from the model? Technically, a controller managers one view and one model. Also, why are there two sub Student models? Neither the view nor the controller should care how the model is created, only that it adheres to a specific contract. Also, in more "pure" implementation of MVC, the view and the model should no nothing about each other and all interaction is done through the controller - this part I find hard to swallow, as it means duplicating a bunch of code, where adhering to a prescribed contract/interface would solve the issue :P Commented Nov 6, 2017 at 20:52
  • @MadProgrammer Student is model class that has simple fields and getter and setter methods. Student view has JTable and it requires TableModel to display the student information. Student view doesn't know about any of these models, but it only accept TableModel as an argument. This Table Model is defined by Student view data model class. I built model interface as if in future i don't want to see student info, then I can simply remove student view data model. Commented Nov 7, 2017 at 8:37
  • @MadProgrammer I didn't get your point for duplicate code and separating Student from model. How can I minimize my design. It would be better if you provide an answer with pictures Commented Nov 7, 2017 at 8:57
  • Part of the problem is, you're trying to apply a MVC around a MVC, Swing is already a MVC. To my mind, the Student model should provide simple information about the number of students and the ability to get them, it's then up to the view to present in what fashion it needs, albeit a JTable, JList, so other navigable form. In a "pure" MVC, where the view and model don't know about each other, the controller begins to duplicate functionality, in particular of the model, as the view requests information from the controller, which the controller forwards to the model and back again Commented Nov 7, 2017 at 9:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.