Are modules Absolete?

Wakane

Member
Joined
Oct 9, 2002
Messages
8
Hi, All!

Before, Ive always put my utility subs/functions in a module.

for example module "useless" contains one sub

Public Sub printHello()
MsgBox("Hello")
End Sub


But since the true classes & OOP are now coming in. I can just put the sub as a shared sub in Useless class.

for example class "Useless" contains one sub


Public Shared Sub printHello()
MsgBox("Hello")
End Sub


I know there are differences in calling them. One is "printHello()", the other is "Useless.printHello()"

But I feel in this particular issue, class is superior, because you can see the grouping (by class name) directly in the code. So something like "StringUtility.ConvertToNumeric("012")" and "DatabaseUtility.GetDatabaseName()" seems to be nicer to read, especially when youve got lots and lots of utility subs/functions.

So does it mean that modules are absolete? What are the advantages of using modules than classes in this particular issue (not as the whole, just this issue)?
 
I dont think there are any advantages in using modules at all. Under the hood, your modules just get compiled as shared methods of classes anyway. I havent used a module since the first time I broke out VB.NET.
 
Thanks

Originally posted by divil
I dont think there are any advantages in using modules at all. Under the hood, your modules just get compiled as shared methods of classes anyway. I havent used a module since the first time I broke out VB.NET.

Really? I didnt know that! Thanks. So I think Ill probably go only with classes, because I think its more organised. :)
 
Modules just give you another way to organize information other then a class. If you dont need to instantiate multiple copies of something then why not just make it a module? Its just there to give you another choice is all.

Theres also structures now too, which replaced user defined types. Definitely a nice addition but obviously arent as flexible as a class or module because of restrictions they have.
 
There is really no point in using modules when you could use shared methods of classes instead.
 
Absolutely, divil. Microsoft made two mistakes when they designed .NET: Microsoft.VisualBasic.Compatibility and modules.
 
Hmm..

Obviously I still have much to learn about .NET.

*zips his mouth and returns to researching*
 
How about structures?

Originally posted by divil
There is really no point in using modules when you could use shared methods of classes instead.

Could we say the same regarding the structure and classes relationship? Can a class really replace structure completely (never mind the speed differences for now)?
 
No, structures and classes are equally useful, they are value and reference types, respectively.

Classes derive from MarshalByRefObject, structures do not.
 
Back
Top