Class with only shared members/procedures VS Module

  • Thread starter Thread starter Daniel Fernandes
  • Start date Start date
D

Daniel Fernandes

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
 
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
 
* (e-mail address removed) (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.
 
"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.
 
Misread your question a bit. Both items I mentioned apply to both cases you
mentioned.
 
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.
 
David said:
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
 

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

Back
Top