Command mode in Windows form Programming

Source: Internet
Author: User

Command mode, or similar mode. I personally think it is a C ++ or Java style, but it does not mean that these modes are not required when VB or Windows form is used for programming.

The core idea of the command mode is to make the Interface ClassCodeSeparated from the Action Code, for example, the code for creating a menu (not an applicationProgramCall the class that creates a menu, but a menu class), and there is no specific operation code in its action (click) code. How can this problem be achieved? There is a reference to the command interface in the menu item class. Its click process calls the execute method of this command. The specific command object is bound by the app class (For details, refer to the gof design mode ).

This is basically not required for VB or Windows form development, because through the event mechanism, interface operations and actions can be implemented in their events. The interface components have been designed. You can process the action code in the corresponding event handler. However, for some requirements, you still need to use the command mode to do something.

For example, you can use the command mode to record user actions, determine whether the operation has the permission, or add undo to the operation (the classic command mode is required. In command mode, this type of code is isolated from the interface form. For example, you can use the following code in a button-click event:

_ Testcommand. Execute (...)

In this command implementation, you can check permissions and record actions.

In addition, for some actions triggered by events, you can also use command to implement specific actions and remove the specific operation code from the form.

In VB 6, the author basically uses the creation of a series of command processes in the module to perform operations. I personally think that the idea of command is to isolate interfaces and actions. Bob's Agile Software Development contains an example of a photocopier application.

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.