Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, All!

 

Before, I've 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 you've 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)?

Posted

Thanks

 

I don't 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 haven't used a module since the first time I broke out VB.NET.

 

Really? I didn't know that! Thanks. So I think I'll probably go only with classes, because I think it's more organised. :)

Posted

Modules just give you another way to organize information other then a class. If you don't need to instantiate multiple copies of something then why not just make it a module? It's just there to give you another choice is all.

 

There's also structures now too, which replaced user defined types. Definitely a nice addition but obviously aren't as flexible as a class or module because of restrictions they have.

Gamer extraordinaire. Programmer wannabe.
Posted

Hmm..

 

Obviously I still have much to learn about .NET.

 

*zips his mouth and returns to researching*

Gamer extraordinaire. Programmer wannabe.
Posted

How about structures?

 

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)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...