Modules versus classes with shared methods?

  • Thread starter Thread starter Chris Ashley
  • Start date Start date
C

Chris Ashley

Is there any disadvantage to using a class with shared methods as
opposed to a module? I suppose the end result is the same, but I'm
curious about any other issues.

Regards,

Chris
 
The only difference I have seen is, I find it easier to work with classes,
and unless you want to call

MyClass.MySharedMethod

instead of amodules where you just call

MySharedMethod

Which you can do with a class with

imports MyClass

at the top... I see no real difference though... At elast for what I need.
 
Chris Ashley said:
Is there any disadvantage to using a class with shared methods as
opposed to a module? I suppose the end result is the same, but I'm
curious about any other issues.

Two things you don't have to do with Modules:
- Write "Shared" in front of every member
- Import the class at project level

The result is the same.
 
Classes allow you to have Private and Protected variables as well as the
ability to use inheritance. Modules don't really.

I only use modules for what I like to call utility functions.. functions
that are totally object independent that do useful routines and don't really
handle important information..

If you are modelling objects then use classes in my opinion...that's what
they are there for ;)

All the best,

Jon
 
Is there any disadvantage to using a class with shared methods as
opposed to a module? I suppose the end result is the same, but I'm
curious about any other issues.

Regards,

Chris

In fact, at the IL level there is no difference. A module is converted
by the VB.NET compiler into a sealed class with all shared methods. The
difference is mostly about style. Personally, I would use a class with
shared methods rather then a module - but that's me.

Tom Shelton
 
Back
Top