Is MVC mode not easy to use? Why not try move?

Source: Internet
Author: User

The Application of MVC pattern in programming is a great idea. "Data Model" can encapsulate data related to the application's business logic and the data processing method. "View" can display data purposefully; the controller can act as an organizational unit at different layers to control application processes.

However, you may be confused when 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, and finally find that too much code is inserted in the control layer.

LinkedIn's software engineer Conrad Irwin also encountered the same problem, so he began to use another model:Move: models, operations, views, and events ). 

Recently, Conrad Irwin shared his views on this mode on his blog.


Overview 

Irwin makes a simple definition of the move mode in combination:

  • Models encapsulates everything that the application knows;
  • Operations, encapsulate everything the application has to do;
  • Views to help users interact with applications;
  • Events, used to Securely connect all these components.

To avoid spaghetti code, the figure shows which type of objects are allowed to be operated. For example, a view allows you to listen to events generated by a model. An operation allows you to modify a model, but the model does not involve views or operations.

Models) 

This example uses a "user" object as a prototype. It must have at least one email address, user name, and phone number.

In a move mode, only the knowledge is encapsulated in models. This means that apart from the get and set functions, they can include methods such as checking whether the user password is correct, but they do not include functions such as saving the password to the database or passing it to an external API, this will be done by operations.

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 are the actors in the move mode. It is responsible for modifying the model, displaying the correct view at the right time, and responding to events triggered by user interaction. In a well-decomposed application, each sub-operation can run independently.

This method is a little exciting, that is, after the program is started, the entire application itself can be treated as an operations. It generates as many sub-operations as possible as needed, and each sub-operation runs in parallel. When all sub-operations are completed, the program also exits.

Views) 

The login page is a view that displays some text boxes to users. When a user clicks the "login" button, the view generates a "loginattempt" event, which includes the user name and password entered by the user.

The content that users can see and the interactions they can feel are all supported by the view. They present application feedback in a form that users can understand, and convert simple user interaction into meaningful events. More importantly, the view does not directly change the model. They only initiate events to operations and then wait for the events initiated by the model by listening.

Events) 

When a user logs in, the view initiates the "loginattempt" event. After the login operation is complete, the "currentuser" model will initiate an event to notify the application that the login status has changed.

Event listening allows move (and MVC) to implement control inversion, and allows the model to update the view. This is a powerful abstraction technique that allows components to be coupled without interference.

Why is it now? 

Of course, Conrad Irwin does not want to be considered as suggesting that the MVC pattern is poor. Such a large application architecture has been very successful over the past few decades. However, a few decades later, new programming technologies have become increasingly popular, so you will gradually become confused when using them.

The MVC pattern is really amazing, but after all it was designed for the old technology decades ago. The move mode is based on the upgrade, so that you can better use the existing new tools.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.