473,569 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1769
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.googl e.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******** ******@TK2MSFTN GP10.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.googl e.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:<slrncidld i.8i3.df*****@w oofix.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
1529
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 "add class" or "add module". My understanding is a module is a class so what is the difference? Correct me if I'm wrong....a module allows you to...
3
1869
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: public module db Friend ConnectionString As String = "" Public Sub InitializeDB(ByVal AConnectionString As String)
4
13892
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
10964
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 when should I use module or class, because no matter i use module or class, i always could get the results that are what i want. but just the declare...
29
1951
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 MyClass ClassConst = myObj.ConstantString Inside the class MyClass
10
5477
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 advance
9
2337
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 = CDec(txbInv.Text) Wage = CDec(txbTotWage.Text)
13
2681
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 module does the same as a class but cannot herite or be herited. 1)Is that right? 2) So i guess this module does exactly the same as the class?
7
1518
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 that? -- Regards, Diego F.
0
7701
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.