MVC in Windows form Programming

Source: Internet
Author: User

MVC consists of three roles: model, view, and controller. The model represents the specific data and behavior. The view represents the data display. The controller obtains user operations, changes data, and controls the view display. Its core lies in separating the view from the model and the controller from the view.

For Windows formProgram(VB 6 is similar). The controller is basically a built-in form and various components (Controls) of the system, and does not need to be written for user operations.Code, You only need to write the specific operation in the code of the Action event response.

It is a model design. It is generally a class or a group of classes that have specific data and operation code.

For data display, that is, a view, it can be a method, a group of methods, or a class. The key lies in data refresh. There are two methods:

First, define some events in the model to update or change the data. subscribe to these events in the view and write the specific view update code in the event trigger method;

Second, call the method or class for refreshing data display in the code after the action is completed to change the view;

The first method of personal preferences is that the program on the Web must use the second method. In this way, the model class is more pure. However, it seems that it is not good for the form program to update interface data when something is okay, it is also difficult to save the user status, such as the selected data (table. In addition, the final update data of an operation sometimes requires context and is uncertain. It seems easy to control and encapsulate data through event triggering.

Although most of the Windows form programming can be completed without the need to pay attention to the MVC role, I personally think it is worthwhile to learn something from it to improve the program design and code quality.

Related Article

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.