Preface
There is time today just to have to write about these nouns. For me. In fact, so many nouns, thought in the root of the project is to be based on the actual, personnel configuration to do reasonable optimization, can not talk on paper, and can not be afraid of the former. Then reasonable phased architecture and good code is the key, this article will be two ideas, the first introduction, and then say the pros and cons, the actual development.
OneMVCIntroduced
MVC (Model-view-controller): M refers to the logical model, v refers to the view model, and C is the controller. A logical model is available for multiple views
model, for example a batch of statistics data you can separate represented by a histogram or pie chart. A view model can also be available for multiple logical models.
Using MVC's
The goal is to separate the implementation code for M and v. so that the same program can use different forms of expression . The purpose of C exists is to ensure the synchronization of M and V.
Once m changes, V should be updated synchronously.
Second, the use of MVC in Android
1. View layer: Generally adopt XML file to describe the interface, can be easily introduced when using. Of course. How much more you know about Android,
It would be possible to think of it as a view layer in Android as well as javascript+html, and of course, there is a need for communication between Java and JavaScript. Fortunately,
Android provides a convenient communication between them to achieve.???
? 2. Control layer (Controller): This layer should be the most connected to the business layer. Is the user can operate the entrance, in the Android only has the activity. There is a controller in iOS,
on this side . What you need to do in activity is business orientation. Detailed implementation module function can be encapsulated to the model layer, long-time operations such as download, upload, etc. can be put threads or services.
3. Model: The operation of the database, the operation of the network, etc. should be processed in the model, of course, business computing and other operations must be placed in the layer.
There are also data models that can be placed on this layer.
Third, MVC strengths
From the user's point of view, users can be based on their own needs. Choose the right way to browse your data.
For example, for an online document,
user can choose to HTML page read,
the logical layer is completely separate from the interface. The biggest advantage is: interface designers can directly participate in the interface development, the program Ape can focus on
on the logical layer. Instead of having the designer put all the material in the hands of the developer, the developer implements the interface.
In the eclipes work
Android in Development In a more simple way, Designers Design the interface in DroidDraw. Save as XML.
You can see the designer's interface by opening it directly in the eclipes.
Iv. introduction of the MVP
MVP as an evolutionary version of MVC, the equivalent of a similar MVP: m-model-model, v-view-View, p-presenter-representation.?
controlller/presenter plays the role of logical control in MVC/MVP.
The role of the process.
and the MVP and MVC The most different one The point is M and V is not directly There is no direct relationship between model and view, both of which
MVP structure diagram
for the UI.
< Span style= "Color:rgb (63,63,63); line-height:30px;" > do basically need to be asynchronous to operate the UI in Mainthread. So to view a reasonable. Also
presenter interaction with view, model using interface-defined interactions to further achieve loose coupling can also be achieved through an interface more convenient to carry out
Unit Test.
Iv. advantages and disadvantages of MVP
1. Strengths:
Presenter this layer handles the distribution of various logic of the program, receiving feedback commands on the view layer UI, timing commands, system commands, and other commands to distribute the processing
Logic handed Model layer to do detailed business operation. Here you can see that what you're doing is being pumped out to reduce activity and view business .
the coupling, which facilitates maintenance, easy to develop, reduced activity in code and business extraction modularity.
2. Disadvantages
The MVP architecture will be drawn out of one layer, which is the business distribution, assuming the project is getting bigger and more people. Assume a lot of business. and easy to change, pumping
the first floor will the readability of the variable is reduced. There are also development teams that assume that they cannot persist and that they need to structure again. It is essential to write again, so be cautious.
V. Introduction of MVVMMVVM is first based on the evolution of MVC, and here's what MVVM stands for. The MVVM pattern consists of three parts: model– on your behalf. Basic business logic. view– display content,viewmodel– the object that ties the previous two together.
a ViewModel interface provides two things:actions and data. Movement Changethe lower level of the model (click Listener. Monitor text changes listener and so on), and the data is the model content, representingthird-party library: Robobinding and so on, GITHUB:HTTPS://GITHUB.COM/ROBOBINDING/ANDROIDMVVM.
Vi. advantages and disadvantages of MVVM1. Strengths
ViewModel is roughly the MVP of the presenter and MVC controller, and the view and ViewModel without the MVP interface interface, but directly
interaction. the event that data is updated in the form of "binding" is not necessary for developers to write special use cases manually, but to synchronize themselves proactively. Data binding you can
think it's observer . mode or Publish/subscribe mode, the principle is to use a unified centralized way to achieve frequently needed to implement the data update
problem. than MVP. MVVM simplifies business-to-interface dependencies, optimizes the way data is frequently updated, and even provides a
Effective solution mode.
2. Disadvantages
MVVM is a data model-bound view that reduces code and reduces data updates, but assumes responsibility for business logic or high-frequency business changes, and for code justification
solution will Have been reduced. And to use a third-party architecture. This is the last thing I like.
Specific explanations for MVC, MVP, and MVVM in Android