Add a method to a class in vb.net

Source: Internet
Author: User

A class is a publicly-owned sub or Function procedure that is declared by a user in a class.
For example: The following code adds a withdrawal method to a account that allows the user to add the public function process to the class module:

Public Function withdrawal (Byval Amount as Currency,_
Byval Transactioncode as Byte) as Double
  "(Code to perform t He withdrawal and return the
  ' new balance,or to raise ' overdraft error.
End Function

If the class account has the balance attribute, the user can also not return the balance value, because the user can easily access the Balance property after the withdrawal function is called, so the user can replace the function with a public process.
Note: If you find that the withdrawal is set to a procedure, after each call to the withdrawal process to access the Balance attribute value, then the withdrawal set to return balance value, will be more efficient. This is because for the properties of a class, the value of getting an attribute at a time is also calling a common function propertyget and accessing some public variables, regardless of whether the PropertyGet function is explicit or implicitly declared.
In the class module, by defining the attributes and methods, it constitutes a class external interface, just as the data encapsulation of the class, if the user declare a process as private, then it can not form part of the interface. This means that users can change the operation of the entire program by changing some of the private internal processes within the class without having to change the code that uses the class.
More importantly, users can also change the functions of the whole program by changing the Sub or Function procedure of the public as the method of the class, without involving the code that uses the class, just as the parameter of the procedure cannot be changed and the return type of the function, and from the outside, the user cannot change the interface of a class.
Hiding the specifics of a class beyond the interface of a class can be considered a manifestation of the encapsulation of a class, which allows the user to improve the performance of one method of a class without changing the code of the class, or to completely alter the function of a class's methods.

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.