android MVP 中 P层应该去做哪些事?
高洛峰
高洛峰 2017-04-18 09:15:44
0
6
494

我在实际使用中发现,P层除了请求网络,然后把请求回来的数据解析成JavaBean,然后传递给V层,然后就发现没他什么事了,非常尴尬.
难道写一个P层只是为了用来请求网络吗?
求大神轻喷..
菜鸟想在这里请教一下,MVP中的P层 ,应该去履行哪些职责?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(6)
大家讲道理

P layer connects model and view.
The data is loaded in the model layer, and the P layer calls the method of the model layer.
The effect display is processed in the view layer. The P layer calls the method of the model layer. After getting the data, it interacts with the view layer. I don’t know if this explanation is clear.

伊谢尔伦

The main task of the p layer is to handle various logics

I think one of the shortcomings of MVP is that it requires writing a lot of interfaces and code. If an activity has few enough tasks (for example, there is only one listview requesting the network), the logic can be written directly in the activity. There is no need to force MVP

伊谢尔伦

I think data (including network requests and JSON parsing) should be placed on the V layer. Set up a callback interface to send the processed data to the P layer. If the data needs to be updated to the V layer, the P layer will push it to the V layer. render. (Words from a newbie)

Ty80

presenter 主要是做逻辑层,你说的数据加载这些被许多人称为ModelLayer, the presenter just controls various logics. If you can take a look at this video and the google open source sample on github

小葫芦

Presenter coordinates View and Model. The intuitive feeling is the control logic between V-M.

Model changes callback to View through Presenter; View changes callback to Model through Presenter; in this way, Model and View are not tightly coupled, which improves encapsulation and reuse value to a certain extent, which is stronger than MVC...

洪涛

Presenter is simply the bridge between View and Model. On the one hand, the Presenter method is called in the View to implement logical control, and then the Presenter calls the method in the Model to perform specific data request work, and then through callbacks, the Presenter Pass it to View and render the data. I think you need two examples to understand the MVP model. I recommend two:
1, StylishMusic
2, LookLook

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template