The full name of MVC is Model-View-Controller, which was first proposed by Trygve Reenskaug on the Smalltalk-80 system in 1970. SmallTalk is explained in Baidu Encyclopedia as follows: Smalltalk is recognized as the second object-oriented programming language in history and the first true integrated development environment (IDE). Let's take a picture to illustrate the working mode of MVC! The small red box in the picture is the working mode of MVC
MVC is a framework pattern rather than a design pattern Its advantages are:
The disadvantages are:
Android pseudo code implementation of MVC The code and data in the following picture do not match. It is just for the convenience of understanding how to write MVC in the code. If you need to see examples, you can go online to learn about it. I am lazy here:)
That is, data, which can be the content in the database or the List collection written in the code.
By performing operations in the Controller that are passed by the user in the View, the data in the model is accessed, and then the state in the View is changed. MVP is an evolved version of MVC, and its full name is Model-View-Presenter. The emergence of MVP is mainly to solve the problem of high coupling between View and Model in MVC, while also bringing good scalability. The three roles of the MVP model:
The main actor is the bridge between View and Model. It gets data from Model and returns it to View layer, so there is no coupling between View layer and Model layer, thus extracting business logic from View layer.
Model mainly provides data access functions. Presenter needs to store and obtain data through the Model layer. The Model layer is like a warehouse.
View usually refers to Activity, Fragment or a View control. It contains a Presenter member variable and needs to implement a logical interface. The operations on the View are transferred to the Presenter for implementation. The Presenter calls the View logical interface and returns the result to the View element. Let's take a look at the working mode of MVP. From the figure we can see the difference between MVP and MVC:
Android pseudocode implementation of MVP The code and data in the following picture do not match. It is just for the convenience of understanding how to write MVC in the code. If you need to see examples, you can go online to learn about it. I am lazy here:)
Why don't you worry about whether it is MVC or MVP? The ultimate goal of MVC and MVP is to separate data and UI so that they do not affect each other. So how can we do it without any entanglement? Have you heard of object-oriented? If you have heard of it, listen to my understanding~
Encapsulation, polymorphism, inheritance. The teacher seems to have taught us this way, so what does it mean by polymorphism, encapsulation, inheritance?
Encapsulation is to encapsulate things that users don't want to see, which can be used in Private in object-oriented. Attributes, write the content that users don't want to see in here. For example, for the play function on a radio, the user doesn't need to know how to play the radio, it only needs to know that pressing this button can play.
Polymorphism refers to the multiple forms of an object, mainly manifested as: behavioral polymorphism and state polymorphism. Behavioral polymorphism is like a father having multiple children, each child is different, but they all have the same father; state polymorphism is like each child having many states in a day, including eating, studying, and sleeping.
A friend of mine told me that inheritance is actually the biggest misunderstanding of object-oriented programming. Inheritance can be understood as an object that is composed of multiple small objects; for example, the object of a person is composed of hands, feet, head, etc. Therefore, we don't need to remember inheritance, as long as we have a deep understanding of each object, we can describe the object clearly! So what is the relationship between MVC, MVP and object-oriented? First of all, both MVC and MVP require that data and UI do not affect each other, so isn’t object-oriented the same?
The object is what we call the user, which is also the View in MC or MVP. We show what the user needs, and if the user doesn't need it, we encapsulate it and provide a method for you to call it. Isn't this very similar to MVC or MVP!
At the same time, object-oriented programming also requires the subdivision of object behaviors. For example, people can run and swim... Is this the same as the Model in MVC, which needs to handle different user operations?
***Object-oriented programming also requires a state to control, such as the human brain. The brain is used to coordinate the balance of hands and feet. |
<<: iOS grabs HTML, CSS XPath parses data
>>: Decryption - The mysterious RunLoop
What are the problems that most people have in us...
The ancients used maps to depict spatial informat...
Since the advent of the Meizu brand, the Meizu No...
Recently, the local epidemic in Jilin has attract...
According to Master Chan's analysis of the &q...
In addition to delivering a good product, how can...
In today's Internet age where everyone is a s...
Recently, a 20-square-meter milk tea shop in Shan...
The Chinese mobile game industry, which has been ...
In the era of social dividends, the reason why th...
Review expert: Chen Mingxin, national second-leve...
A friend who does e-commerce asked on WeChat: &qu...
The course comes from Shengfan’s Blue Ocean Virtu...
How many steps are there to extract oil? Find it,...