Use of static functions in VB .NET

sidsiv

New member
Joined
Nov 21, 2005
Messages
1
Programming Experience
Beginner
I am creating a web application using .NET. I am new to VB and to .NET.I need to create functions which add my business classes to the database. Is it a general practice to use static functions(using the shared keyword) in VB .NET? Then there is no need to instantiate the class when I use the function.

eg: There is a class Customer which has several attributes. I include a static function Add in customer which adds a customer to the database. A call to Add would look like this :

Customer.Add(obj)

obj is a Customer object
 
In my opinion that is not appropriate because it doesn't really sound like a method that should belong to the Customer class. Your Customer class should know about itself, but if you want to add it to a container of some sort then that's a job for the container. Note that if you want to add an item to a collection you call a method of the collection rather than the item. I don't really know what the structure of your app is like but that doesn't sound like a member of the Customer class to me.
 
Back
Top