Module vs Class Module

  • Thread starter Thread starter Brad Parks
  • Start date Start date
B

Brad Parks

Are there any performance or memory-usage benefits of placing public
functions and subroutines in a Class Module rather than a standard
module?
 
All a module is is a sealed class with all shared properties/methods etc.
I'm not sure if you are referring to 'Class Module' as in the old VBA sense
or as a Class. There is not Class Module in the VBA sense equvialent in
..NET
 
Brad Parks said:
Are there any performance or memory-usage benefits of placing
public functions and subroutines in a Class Module rather than a
standard module?

No. A Module *is* a special class:
- all members are automatically declared Shared
- no instance can be created
- it is imported automatically at project level
 
Brad,

* (e-mail address removed) (Brad Parks) scripsit:
Are there any performance or memory-usage benefits of placing public
functions and subroutines in a Class Module rather than a standard
module?

If you are referring to VB Classic (Version 1-6), please turn to one of
the microsoft.public.vb.* groups.

For VB.NET: Modules get compiled to friend classes which are imported
automatically. There are no performance and memory-using benefits when
using a class with shared methods instead.
 
Brad,
If by "Class Module" you are referring to a class that only has Shared
members, then as the others have stated there is no performance or
memory-usage benefits.

However! the biggest benefit I see to using classes with Shared members over
Modules is encapsulation, you are "required" to qualify the name of the
class when you use one of the shared members, ensuring that you know were
that member is coming form.

BTW: You can relax this "requirement" by importing the class itself, which
then allows it to work like a Module for that source file.

For example:
Imports System.Math

Hope this helps
Jay
 
Back
Top