MVC modeThe application in programming is a great idea."Model" can encapsulate the data related to the business logic of the application and the processing method of the data;"View" can realize the purposeful display of data;"Controller" can play an organizational role at different levels and control the process of the application.
However, you may get confused in the process of using this three-tier architecture model.Because you don't know where to put a lot of code, you have to put it in the control layer. Finally, you find that there is too much code in the control layer.
LinkedIn Software EngineerConrad IrwinHe also encountered the same problem, so he began to use another mode:MOVE,That is, Models, Operations, Views, Events.
Conrad Irwin recentlyPersonal blogShared some views on this model.
summary
Irwin first gives a simple definition of MOVE mode in combination with the figure above:
Models,Encapsulates everything you know about the application;
Operations,Encapsulates everything the application needs to do;
Views,Help users interact with applications;
Events,Used to securely connect all these components.
In order to avoid spaghetti code, the figure shows which types of objects are allowed to operate.For example, views allow listening to events generated by the model;Operations allow you to modify the model, but the model should not involve views or operations.
Models
Here we take a "User" object as the prototype. It has at least one email address, and may also have a user name and phone number.
Only knowledge is packaged in a MOVE model.This means that in addition to the Get and Set functions, they can include such methods as checking whether the user's password is correct, but they will not include such functions as saving the password to the database or passing it to external APIs, because Operations will complete these tasks later.
Operations
For applications, a common operation is user login.This is actually composed of two sub operations: first, obtain the email address and password from the user, then load the "user" model from the database and check whether the password matches.
Operations is an actor in MOVE mode.It is responsible for modifying the model, displaying the correct view at the correct time, and responding to events triggered by user interaction.In a well decomposed application, each sub operation can run independently.
The operation in this way is very exciting, that is, after the program is started, the entire application itself can be regarded as an Operations.It generates as many sub operations as needed, each of which runs in parallel.When all sub operations are completed, the program exits.
Views
The login page is a view, which is responsible for displaying some text boxes to users.When the user clicks the "Login" button, the view will generate a "loginAttempt" event, which contains the user name and password entered by the user.
The content that users can see and the interaction they can feel are supported by views.They will present application feedback in a form that users can understand, and they can also transform simple user interaction into meaningful events.More importantly, views do not directly change the model. They just send events to Operations, and then wait for events sent by the model through listening.
Events
When the user logs in, the view will initiate the "loginAttempt" event.After the login operation is completed, the "currentUser" model will send an event to notify the application that the login status has changed.
Event monitoring enables MOVE (and MVC) to implement inversion of control, allowing the model to update the view.This is a powerful abstraction technique that allows components to be coupled together without interference.
Why now?
Of course, Conrad Irwin does not want to be considered as suggesting that MVC mode is poor. This large-scale application architecture has been very successful in the past decades.However, several decades later, new programming technology has become more and more popular, so you will gradually have some doubts in the use process.
MVC mode is really great, but it was designed for old technology decades ago after all.MOVE mode is an upgrade based on it, so that you can make better use of the existing new tools.