Differences and comparisons between class modules and standard code modules

Source: Internet
Author: User

In actual programming, when to use the class, select the standard code module? The difference between a class and a standard code module is primarily conceptual. You can use a class if the user is working on one or several specific objects. The object's action is the method of the class, The properties of an object must be implemented using the property procedure of the class. Conversely, if a user has a procedure that is directed at a common set of transactions, rather than some particular object, Then this routine is best implemented in a standard code module. And the difference between the class module and the standard module is also the different way of storing the data. The standard module's data has only one backup, which means that when the value of a public variable in a standard module changes, it will get the same value when the variable is read later in the program. The data for a class module exists independently of the class instance (that is, each object created by the class). Similarly, the data in the standard module exists within the scope of the program, that is, it exists in the lifetime of the program, and the data value in the class instance exists in the object's lifetime, and it is created with the object's creation, Disappears with the object's revocation. Finally, when a variable is declared public in a standard module, it is visible anywhere in the project, while the public variable in the class module is accessible only if the object variable contains a reference to a class of instances.
In general, classes are used in the following two situations:
(1) Users want to use class methods and attributes to improve the encapsulation of the Code;
(2) The user wants to create a large number of objects of similar nature.
In other cases, standard code modules are generally used.

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.