473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Class with only shared members/procedures VS Module

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
6 1761
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
* 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ray | last post by:
Greeting, I'm still grasping the class concept so bear with me. I have a vb.net app in which I wrote and placed various public functions for later reference. In vb.net there is an option to...
3
by: Phillip Ian | last post by:
Just a quick architecture question. I'm just looking for discussion, not a flame war, please. In the past, I've tended to use a public module for my data layer functions. Something like: ...
4
by: Brad Parks | last post by:
Are there any performance or memory-usage benefits of placing public functions and subroutines in a Class Module rather than a standard module?
16
by: A_PK | last post by:
Hi, I am a VB.net beginner, I do not know what are the major difference between Module vs Class. Could someone guide me when is the best situation to use Module or Class. I have no idea...
29
by: Michael D. Ober | last post by:
Is there any way to create a constant in a class that can be used both with an instantiated object and without. For example: dim ClassConst as string = myClass.ConstantString dim myObj = new...
10
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
13
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a...
7
by: Diego F. | last post by:
Hello. I have a windows forms application with one form. I added other class files too. By default, the applications starts in the form class, but I want it to start from other class. How can I do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.