PC Review


Reply
Thread Tools Rate Thread

Class with only shared members/procedures VS Module

 
 
Daniel Fernandes
Guest
Posts: n/a
 
      20th Aug 2004
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
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Aug 2004
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


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Aug 2004
* (E-Mail 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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
JD
Guest
Posts: n/a
 
      20th Aug 2004
"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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
JD
Guest
Posts: n/a
 
      20th Aug 2004
Misread your question a bit. Both items I mentioned apply to both cases you
mentioned.

"JD" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>



 
Reply With Quote
 
David
Guest
Posts: n/a
 
      21st Aug 2004
On 2004-08-20, Daniel Fernandes <(E-Mail Removed)> 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.

 
Reply With Quote
 
Daniel Fernandes
Guest
Posts: n/a
 
      23rd Aug 2004
David <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> On 2004-08-20, Daniel Fernandes <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. Roberto Rasto Microsoft VB .NET 2 11th Jan 2008 09:05 PM
Difference between Form's Class Module and Class Module tobesurveyor via AccessMonster.com Microsoft Access VBA Modules 4 14th Apr 2006 01:08 PM
calling standard module procedures from event procedures =?Utf-8?B?b3NzaWFu?= Microsoft Access VBA Modules 2 9th Feb 2006 01:26 PM
Use of shared class members in ASP.NET Mr Newbie Microsoft ASP .NET 11 5th Dec 2005 12:58 PM
Use of shared class members in ASP.NET Mr Newbie Microsoft VB .NET 11 5th Dec 2005 12:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 AM.