我不是MVC/MVP一切的专家,但这里是我大部分时间。
For simple applications where UI automation and testing is not an issue, I go with the GUI depending on a concrete controller (My view actually instantiates the controller). What I do though is make sure the GUI implements some view interface that the controller takes as a parameter in its constructor.
In that way, I don t need to use any event or observer-like behavior: the controller has access to the view interface and the view holds a controller as its member.
The problem with this approach in my opinion is that it is not really test friendly. While some may argue that MVP (Model View Presenter) may be based on this approach, I don t like the fact that the controller cannot exist without a GUI object being instantiated. Even if you pass a controller as a parameter of the GUI object in its constructor, I tend to consider it more like a hack.
Another issue with that approach is that the GUI actually is not passive enough. I like the logic in my UI to be handled by the controller, not the other way around . But that may just be a personal choice.
如果测试成为一个大问题,我确信,全球倡议甚至不知道控制者,因为控制者是瞬息万象(直接或通过依赖注射)的对象。 http://martinfowler.com/eaaDev/SupervisingPresenter.html” rel=“nofollow”>supervising Controller。 这种做法有助于进行大量测试,因为我实际上能够通过提供假执行《全球倡议》或甚至重新使用我的控制员,以不同的方式执行这一看法,来改变整个国际统一倡议。 在此情况下,国际律师联合会实际上可以提出控制人将处理的事件,但只有控制人才能修改基本模式,或在必要时推动对观点的修改(而不是控制人对数据进行更新的看法)。
Just my 2 cents...