MVP: Should the View implement a Presenter's interface or vice versa?

為{幸葍}努か 提交于 2019-11-28 20:40:58

I think you should have used the word 'defines' in your question instead of 'implements' and if thats the case then it does not matter which class defines the interface.

You could do something different by defining the interfaces in its own files. At the end of the day all that matters is the Presenter implementing the Presenter interface and the View implementing the View interface.

@deepak these are valid concerns . Word is infect implementation not definition .

Let me explain . In first example presenters hold the contract to what view must implement in other words drives what should be implemented by views a classical MVP approach .

Things get confusing in second example. Where Presenter has no control over what view must implement . This is not MVP and google is calling it as MVP . There is no way you can test the views with JRE /unit tests using this approach . That does not make it bad though just not MVP and google should not call this MVP or they must explain as to why is it an MVP ?

@Saket Bansal separating out interface is not correct approach . It will result in hard to maintain code as application grows .

In my opinion you can take either approach , I remember google saying some where first one worked for them for adwords and second for wave .

Any how you should also look at framworks like GWTP or ERRAI from jboss

In the second tutorial the code was changed to using a Presenter interface (defined in the view) to accommodate using UiBinders and Java generics. I think the Presenter interface was moved to the View interface as they both share the same generic T.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!