Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

when to use a module v class 3

Status
Not open for further replies.

markSaunders

Programmer
Jun 23, 2000
196
GB
what is the fundamental difference between using a module and using a class?<br><br>i seem to be having a little difficulty deciding when it is appropriate to create a class for something and when i can bundle it up in a module.<br><br> <p> Mark Saunders
 
A code within a module generally is available to your entire project. Within a module you can dimension global variables etc. <br>A class on the other hand must be instantiated except where its instancing properties are set to Global Multiuse. <br>The class module can also be used within transaction server to facilitate transactional processing and using the implements Keyword can provide a limited form of inheritance. <br>The general rule of thumb that I use is that if you wish to encapsulate certian functionality and control the interface to that functionality then you should use a class. <br>I only use modules for project wide declarations such as certian API calls and global declarations<br><br><br>I hope that this clears it up a little for you <br><br><br>
 
Just note an important issue. When building high-traffic applications, you should consider overhead of creating and destroying objects, specially when putting Data Access logic into class modules. MSDN recommends to put the data access code into a standard module vs class modules. It also has a statistical analysis to show this.

For more info search MSDN using this expression in search pane:
&quot;Visual near Basic near Live near Techniques&quot;

Also you may want to run a startup code when your COM dll or exe loads for the first time, like reading the ConnectionString of the database from registry or an .INI file. In this case you should add a standard module an put the initialization code into Public Sub Main.

But in normal cases, follow the USE CLASSES strategy.
 
thanks for the pointer, will definetly check out the MSDN. suspect the amount of data-traffic would be enough to make a difference.
cheers
 
The whole purpose of classes is the encapsulation of data and functionality. They are there to model process.
Use a class where you have a standard interface to something that you are modelling and it then doesn't matter on how you implement it inside!
Have a look at UML on pointers on object modelling and that will give you a much clearer idea about using classes.

james :)
 
I know this is probably obvious to all, but the use of DCOM for distributed deployment of apps makes the use of classes a must.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top