android - What is Android's MVP model? What is the difference from ordinary writing event handling functions?
高洛峰
高洛峰 2017-06-17 09:16:12
0
2
1045

What is Android’s MVP model? What is the difference from ordinary writing event handling functions?

Does MVP have an extra presenter class to hold the Android view object, process data and refresh the view?

The difference from ordinary writing of event processing functions is that the code in the event processing function is moved into the presenter class?

But if it’s just this difference, it doesn’t seem to be anything special. Aren’t we all so abstract when writing code? Abstracting business logic together, why should we separate the concept of MVP?

高洛峰
高洛峰

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

reply all(2)
typecho

Personally, the advantages are as follows:
1. The logic is clear, the interface belongs to View, and the data processing belongs to Presenter, so there will not be an explosion of Activity and Fragment. It is very difficult to read the code, and subsequent maintenance and upgrades will also be difficult. Brings great convenience. When I look at the code written by others, I am most afraid that the layering is not clear and it is very difficult.
2. Testing is convenient. The Presenter can be taken out for testing alone. It does not need to be bound to the View for testing. It is easy to troubleshoot errors.

给我你的怀抱

You are right to say that, use presenter specifically to handle views.
Benefits in my opinion:
1. Presenter normally receives the interface of a view. This application of DIP (Dependency Inversion Principle) allows us to rely on abstraction as much as possible, so that any view can be used as long as it implements these interfaces. share these processing logics.
2. The application of SRP (Single Responsibility Principle) can separate and decouple the data processing logic layer from the view

Actually, it’s just that our development is a bit random. According to the OCP principle, it is closed to extension development and modification. An Activity may have v1 v2 v3 version. Then when you modify the code at this time, you may just replace the previous one. Pushing the code over again, or modifying it based on the previous code, is a dangerous and inefficient behavior. If you use MVP, then when you have v2 or v3 versions, you may have added a few controls, or reduce a few controls. If you directly modify the previous code at this time, then the MVP framework is indeed useless, but if you develop in an expanded way, it will be different. There are several more controls. , then write a new interface to inherit the interface of the original view, and then create a new presenter to inherit the old one, and write new logic in it, which is convenient for maintenance and testing. You only need to test the new code, and the stability of the program is Sex can be enhanced.
So if you write according to the MVP model, the maintainability of your code will become stronger unknowingly.

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