-1
我現在有在我看來的方法,它創建一個從用戶輸入的對象,並將其返回到控制器,其中其稱爲:在MVC中可以在視圖中處理數據嗎?
//In view class
myObject x = new myObject();
x.setAttribute1(TextField1.getText());
x.setAttribute3(TextField2.getText());
x.setAttribute3(TextField3.getText());
return x;
這是否違反MVC中的條款?在控制器中創建對象並在視圖中使用getter方法來設置其屬性會更合適:
//In controller class
myObject x = new myObject();
x.setAttribute1(myView.getTextField1().getText());
x.setAttribute2(myView.getTextField2().getText());
x.setAttribute3(myView.getTextField3().getText());
...
我認爲把「生成」代碼放在視圖中是不對的。也許一個Builder類可以幫助你更多 – Sysix