java - Does this void the MVC design pattern?
问题描述
I am wondering if having a local Student(Model) pulled through using a controller to my view class voids the MVC design pattern.
F.Y.I
I never import my Student model into the view class.
Controller
public void saveStudent(int selectedRow, Student studentChanged){
studentList.getStudentList().set(selectedRow, studentChanged);
}
View
Student currentStudent;
. . . .
public StudentDetailedUI(StudentCntrl studentCntrIn, int selectedRowIn) {
studentCntrl = studentCntrIn;
selectedRow = selectedRowIn;
if (selectedRow >= 0) {
currentStudent = studentCntrl.getStudent(selectedRow);
initComponents();
parseCurrentStudent();
} else {
initComponents();
parseNewStudent();
}
}
. . . .
JButton saveButton = new JButton("Save");
saveButton.addActionListener((ActionEvent e) -> {
if (selectedRow != -1){
currentStudent.setFirstName(firstNameDisplayValue.getText());
currentStudent.setLastName(lastNameDisplayValue.getText());
currentStudent.setUniversity(universityDisplayValue.getText());
currentStudent.setGpa(Double.parseDouble(gpaDisplayValue.getText()));
StudentDetailedUI.this.studentCntrl.saveStudent(selectedRow, currentStudent);
StudentDetailedUI.this.studentCntrl.getStudentListUI();
}
else {
StudentDetailedUI.this.studentCntrl.addStudent(firstNameDisplayValue.getText() +", " +lastNameDisplayValue.getText() +", " +universityDisplayValue.getText() +", " +gpaDisplayValue.getText());
StudentDetailedUI.this.studentCntrl.getStudentListUI();
}
});
My intended functionality is to update an existing student in a list using a list-detail GUI.
解决方案
只要有关更新的所有逻辑都保留在控制器中就可以了,最终您可以在视图中添加一些验证,但控制器仍然应该对联系持久层有最后决定权。
推荐阅读
- python - Python解析添加2个数字的自定义逗号
- python - 如何调用函数来启动 Qthreading?
- c++ - 如何在 Visual Studio C++ 项目中引用 ssleay32.dll
- javafx - 使用 TextFormatter 时无法使用 DatePicker 选择框
- c++ - 在 C++ 中扫描字符串
- javascript - 重用管道中可观察源时的事件顺序是否已定义?
- ruby-on-rails - 当我尝试 gem install bootsnap -v '1.7.2 时出现错误
- java - 矩阵乘法 mapreduce
- git - 无法安装 git - 访问被拒绝错误
- delphi - 如何在执行期间调用在新组件中创建的过程