Machine room cooperation--simple package

Source: Internet
Author: User

The three main features of object-oriented programming are: encapsulation, inheritance, polymorphism, and the encapsulation becomes a good helper when it comes to repeating code with the same logic in a project.

"questions raised"we know that in C/s programming, UI text box design needs to pay attention to many aspects:1. Determine if the text box is empty2. Limit the length of the text box (for example, only 11 digits are allowed for account entry)3. Set the maximum value of the text box (its length cannot exceed the maximum)4. Text box to limit the number type entered is numeric or decimal      The template method is a very good solution to the combinatorial query in the computer room charge system, which is the embodiment of inheritance and polymorphism. In the previous blog, "Computer room reconstruction--ui design and Singleton thinking" mentioned that you can use a large template as the parent form of all forms, so that all form size, font size, background and so on consistent, avoid a lot of duplication of work. But also whim, the implementation of the Singleton method also put in the parent form, this thought can reduce the code duplication, can not think of every subform cannot open, rectify its reason, the singleton mode reduces the program access permissions, the parent class is accessed, the subclass inherits the parent class, belongs to the same level, The class will not be able to access the same way. "Event Selection"for the above text box problem, also once in a blog: "Computer room Charges-module application: Control is empty, all empty, whether it is a number" mentioned, these methods are encapsulated, put into the module moudle.      first look at the basic application of the module:                (1) generally used to store common methods (function) or procedures (sub), these methods are generally static methods(2) These methods can be called directly(3) The module cannot inherit, nor can it implement Interface(4) can be organized into a namespace, called by an outer method
There are many events that can be used by the form programmer, which requires us to choose the reasonable event type according to the actual need, for example, to determine whether the text box input is a number, or whether it exceeds the maximum value and so on the KeyPress event can realize real-time dynamic monitoring The text box cannot be empty, and so on the Button_Click event, if the text box satisfies a fixed length, it is most appropriate to place it under the LostFocus event.
at the same time there is a problem, if a large number of text box controls corresponding to the same KeyPress event, would you like to add the same reference in each text box KeyPress event? Is it possible to consider encapsulating the KeyPress events of different text boxes? There is also an easy way to implement this in the KeyPress event implementation:  
Private Sub txtcard_keypress (sender as Object, e as EventArgs) Handles txtcard.keypress,txtname.keypress, Txtlevel.keyprss
when the public method is encapsulated, sender and E can be passed as arguments. "Summary"

Object-oriented programming, encapsulation, inheritance, polymorphism makes the code easy to simplify, we have to program at different stages to remember these programming ideas, simplicity is our constant pursuit of the topic.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Machine room cooperation--simple package

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: 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.