Put this code in a Class?

E

EManning

I'm very new to VB.Net and am struggling with the concept of classes and when
to use them. I have found some coding to email exceptions to myself that
might occur in this project I'm developing. I would like to make this coding
available to other projects that I will be developing in the future. Should
this coding go into a class? Actually I've done this already and it seems to
work pretty slick. I linked the class to my project and I assume I can link
it to other projects (but I haven't tried that yet).

Is a class the best place for this kind of code? If not, what is?

Thanks for any help or advice.
 
T

Tom Shelton

I'm very new to VB.Net and am struggling with the concept of classes and when
to use them. I have found some coding to email exceptions to myself that
might occur in this project I'm developing. I would like to make this coding
available to other projects that I will be developing in the future. Should
this coding go into a class? Actually I've done this already and it seems to
work pretty slick. I linked the class to my project and I assume I can link
it to other projects (but I haven't tried that yet).

Is a class the best place for this kind of code? If not, what is?

Thanks for any help or advice.

If you want to use it in multiple projects, then I would suggest making
it a public class in a class library project... Then you just have to
reference the dll, in any project you want to use it from, and it's
available to you.
 
E

EManning

This might be a dumb question but a "class library project" would be a
project that contains several classes, all of which could be accessed by
other projects. Correct?

Thanks for your help, Tom.
 
T

Tom Shelton

This might be a dumb question but a "class library project" would be a
project that contains several classes, all of which could be accessed by
other projects. Correct?

Thanks for your help, Tom.

Yep. You've got it.
 
H

Harry

EManning said:
I'm very new to VB.Net and am struggling with the concept of classes and
when
to use them. I have found some coding to email exceptions to myself that
might occur in this project I'm developing. I would like to make this
coding
available to other projects that I will be developing in the future.
Should
this coding go into a class? Actually I've done this already and it seems
to
work pretty slick. I linked the class to my project and I assume I can
link
it to other projects (but I haven't tried that yet).

Is a class the best place for this kind of code? If not, what is?

Thanks for any help or advice.
Classes are one of the three essential building blocks of a project. If you
think in terms of a user interface, a business logic (or worklow) layer and
a data access layer with the last two being classes.

Classes generally encapsulate an entity (eg customer) or contain business
rules.

The user interface is generally only used for display of data, which it gets
from various classes.

Lets say you are dealing with customers. A customer class would ordinarily
contain all of the properties of a customer (name, adress etc) and methods
for fetching the customer data, saving data, deleting data and possibly
listing customers (this is often referred to as CRUD)

If you were selling products you would have a class for product items and a
class for customer orders of these products etc.

Each of these classes would get or save their data by calling on a
specialised class called a data access layer (DAL)

That is, in essence, what classes are about. The subject would easily fill a
number of large books when going into all the possibilities.

Cheers
 
S

schneider

Some other things to think about while building a DLL/Class Library.

Keep in mind the scope of classes, subs, functions. Make things private,
friend, protected, and only public when needed.
Using MS FXCop against your code and reading about the items flagged can
help you learn a lot...

I would read a few atricles on OO:

Introduction to VB.NET Object Oriented
http://www.ondotnet.com/pub/a/dotnet/2003/05/20/introvbnetoo.html?page=1

Schneider
 
E

EManning

Thanks everyone for your replies. I have trouble understanding the
difference between classes and functions and where to use them. Maybe I'll
understand better after I've used classes for a while.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top