Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Class/Function

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
Hello all

I have an asp.net application written in vb that has a shared class. The reason for this is so it can grab a table object from the database.
There are a few other functions and variables in there too but nothing serious.
they are shared so I didn't have to create the class and destroy it every place I wanted to use the function.
I'm thinking this was a bad move, but it's been a while since this was written.

I was looking at inheriting a default page where I could instantiate a class in the page's PreInit sub.
That would give me access to the class without having it shared.

Is it worth the effort to recode it this way? Sorry, I'm a bit new to the web side.

Thanks
 
Hello JB

Because I was reading a few weeks ago that shared functions weren't too good to have and I can't remember why.

I did learn BTW that if you save a variable as a shared then another session could see it somehow. That was interesting.
 
What's better then? A class created through a DefaultPage, inherited by all pages, or a shared class full of functions?
The class also reads and writes to the Session.
 
it's not so much that any design is better than another. However there could be reasons as to why Shared may not be the right choice.
1. should the object be managing it's own scope, or should this be the responsibility of another object (IoC framework)? (I tend to lean towards IoC manging scope instead of the object itself)
2. do you need exactly 1 instance of that object in the system? (usually not)
3. what are to consequences of having more than 1 object at any point in time? (state out of sync.)

I tend to keep my static (shared) objects as light weight as possible. I then delegate the real work to instance objects that can be tested using mocking frameworks and automated testing.

JP Boodhoo coined the term Static Gateway. here are 2 posts on the pattern.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top