By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Class with only shared members/procedures VS Module

P: n/a
Hi there

Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?

I am asking this because I have seen at work a class that declares a
Database connection as a shared member and I wonder if that's a very
bad programming practice..

By the way the environment of execution is ASP.Net.
Cheers
Daniel
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Daniel,

ASPNET environment

A class is stateless
A shared class belongs to all active users from that moment.

A module is nothing more than a class with only shared members.

(The shared class is in my opinion a little bit the same as the cache in
ASPNET)

I hope this helps a little bit?

Cor
Nov 21 '05 #2

P: n/a
* da**************@sesame.co.uk (Daniel Fernandes) scripsit:
Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?


There is one big difference: Modules are imported automatically,
classes with shared members not. Modules are used to "group" methods,
classes represent entities.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

P: n/a
JD
"Shared" data is not shared across web farms or web gardens. May or not be a
problem depending on the data you are storing and if its updateable.

"Shared" data is not multithreaded safe. Cache and Application classes, both
very much like "Shared" members, have synchronization in mind. Application
synchronization is done by the client with lock and unlock, Cache is
mutlithreaded safe. May or may not be a problem depending on the data you
are storing and if its updateable.

"Daniel Fernandes" <da**************@sesame.co.uk> wrote in message
news:eb************************@posting.google.com ...
Hi there

Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?

I am asking this because I have seen at work a class that declares a
Database connection as a shared member and I wonder if that's a very
bad programming practice..

By the way the environment of execution is ASP.Net.
Cheers
Daniel

Nov 21 '05 #4

P: n/a
JD
Misread your question a bit. Both items I mentioned apply to both cases you
mentioned.

"JD" <no@address.org> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
"Shared" data is not shared across web farms or web gardens. May or not be a problem depending on the data you are storing and if its updateable.

"Shared" data is not multithreaded safe. Cache and Application classes, both very much like "Shared" members, have synchronization in mind. Application
synchronization is done by the client with lock and unlock, Cache is
mutlithreaded safe. May or may not be a problem depending on the data you
are storing and if its updateable.

"Daniel Fernandes" <da**************@sesame.co.uk> wrote in message
news:eb************************@posting.google.com ...
Hi there

Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?

I am asking this because I have seen at work a class that declares a
Database connection as a shared member and I wonder if that's a very
bad programming practice..

By the way the environment of execution is ASP.Net.
Cheers
Daniel


Nov 21 '05 #5

P: n/a
On 2004-08-20, Daniel Fernandes <da**************@sesame.co.uk> wrote:

Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?

I am asking this because I have seen at work a class that declares a
Database connection as a shared member and I wonder if that's a very
bad programming practice..


In general that's a bad idea unless you *really* need the connection to
hang around for transaction purposes. ASP.Net does connection pooling
automatically, so the best practice is to grab your connections then
close them as quickly as possible.

As somebody else mentioned, the only difference between modules and
classes with only shared members is the fact that the names in the
module are imported automatically For me, that's enough to avoid
modules entirely.

Nov 21 '05 #6

P: n/a
David <df*****@woofix.local.dom> wrote in message news:<slrncidldi.8i3.df*****@woofix.local.dom>...
On 2004-08-20, Daniel Fernandes <da**************@sesame.co.uk> wrote:

Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?

I am asking this because I have seen at work a class that declares a
Database connection as a shared member and I wonder if that's a very
bad programming practice..


In general that's a bad idea unless you *really* need the connection to
hang around for transaction purposes. ASP.Net does connection pooling
automatically, so the best practice is to grab your connections then
close them as quickly as possible.

As somebody else mentioned, the only difference between modules and
classes with only shared members is the fact that the names in the
module are imported automatically For me, that's enough to avoid
modules entirely.


Thanks all of you for the info.
There is another thing I wasn't sure about is that Shared data is
bound to the ASP.Net application and not per HTTP request. Coming from
the tradition ASP background I didn't thought that was the case so
it's pretty clear now.
I think the biggest issue with keeping a database connection as Shared
data is that as someone mentioned it's not thread safe which means
something will go wrong when two threads want to use that connection
in the same time...

Thanks again

Daniel
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.