MVC and GUI: Where do ActionListeners belong according to MVC pattern?
1. View Responsibility:
Technically, the View should be responsible for maintaining ActionListeners attached totrols the Control the Actionls Controlnlerers attached totroller about actions taken. This way, the Controller is isolated from UI components and can work with any implemented View.
2. Dedicated View Listener:Instead of of Instead.中,您也可以建立一個專門的View Listener。此偵聽器將描述視圖可能產生的操作,例如:
The Controller would then subscribe to the View via this listener, and the View would call didPerformClose when the close button is pressed.public interface MainViewListener { void didPerformClose(MainView mainView); }
Updated Example:
Login View Example with Loose Coupling:
Conider a login. and LoginView have specific responsibilities:
CredentialsView:
Gathers credentials (username and password)
LoginView:Dismisses the view on successful/failed authentication
By using interfaces for communication, both views and the controller can be easily replaced or updated without breaking the Action.以上是ActionListener 應該駐留在 MVC 架構中的什麼位置?的詳細內容。更多資訊請關注PHP中文網其他相關文章!