Modules Vs. Class, what to use?

melegant

Regular
Joined
Feb 2, 2003
Messages
52
Location
NY
I am currently developing an Database app and wanted to set up a class/module that has a bunch of methods that build arrays full of parameter values..

should though i use a module, or a class?

A method would look something like this.

Visual Basic:
Public Sub BldSPAddCustomer() 

With arrParam ' this is an arraylist property in a class for now
.add("@cname")
.add("@addr")
'etc
End With

End Sub
Now, the class I have written allows a person to enter a dynamic number of parameters and thier values to match any stored procedure in the system. If I took it a step further and gave the option of calling pre canned arraylist builders..that would just lesson the code that has to be placed in forms etc...

I suppose it should be a class that i can just build into my inheritence structure..

why then use modules? are they faster? can only a module be built into an dll? i never had the chance to ask my vb teacher in college...
 
You should never ever ever use a module for anything ever.

In my opinion anyway. They are not needed for anything, and have
no advantanges. Instead, use shared methods and members of
classes.

Visual Basic:
'Bad
Module Moo
  Public a As Integer
  Public b As Integer

  Public Function c As Integer
    Return a + b
  End Function
End Module

'Good
Public Class Moo
  Public Shared a As Integer
  Public Shared b As Integer

  Public Shared Function c As Integer
    Return a + b
  End Function
End Class
Because the members are shared, you don't need to make an instance
of the class to use the variables. Just use Moo.a = 5 or whatever
to access the members.
 
Back
Top