In MVP, who should handle navigation?

我的未来我决定 提交于 2019-12-06 03:03:08

问题


It's my belief that the Presenter is the one responsible for handling the navigation aspect of a MVP application. Is this true or are there exceptions?


回答1:


You are right. The model cannot do it, and the view cannot do it.

In my apps, navigation is handled by cascading from the largest presenters to the smaller ones. For instance the overall app presenter gets the whole location, parses it, and sends any relevant pieces to the next presenter for finer-grained detail.




回答2:


I think the view is the only one responsible for the screen navigations. Here we have a good explanation about this "Android-MVP problem" and I have two reasons to think in this way:

1 - Basically for me the screen transitions are not more than a behaviour of views. it belongs of the view state. We know the presenter have to controls the view state through view methods, but is the view that implements this transitions in fact (calling startActivity, for example).

2 - The navigation between screens have some Android SDK dependencies, such as Intents, Bundles, FragmentsManagers, etc... And if you want to use MVP + Clean Architecture (strongly recommended), you "can't" share android dependencies between your presenters, because they should be java only to make the unit tests easier.



来源:https://stackoverflow.com/questions/4110536/in-mvp-who-should-handle-navigation

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