473,406 Members | 2,371 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,406 software developers and data experts.

Class Instantiation

I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.
Apr 10 '06 #1
3 1284
I have a similiar application and instantiate the Database access class in a
module so I can use it in all classes. I probalby will get "Flamed" for this
and if you don't want to do this, you can make all properties and methods
shared in the class. This way, you won't have instantiate the class as a
global.
--
Dennis in Houston
"Scott H." wrote:
I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.

Apr 10 '06 #2
So I could create a global reference to the SQL wrapper class, something like
this:

Module Generic
Public MyConn as New SQLWrapper
End Module

And then use Myconn as a global variable throughout the application. Sounds
like a interesting idea. Is this generally a good practice?
--
Scott H.
"Dennis" wrote:
I have a similiar application and instantiate the Database access class in a
module so I can use it in all classes. I probalby will get "Flamed" for this
and if you don't want to do this, you can make all properties and methods
shared in the class. This way, you won't have instantiate the class as a
global.
--
Dennis in Houston
"Scott H." wrote:
I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.

Apr 10 '06 #3
Yes that works. If you want to use the shared technique then;

public Class SQLWrapper
Shared property ....
Shared method ....
end Class

Then when used in your other classes, etc;

SqlWrapper.property = ....

SqlWrapper does not need to be instantiated.

--
Dennis in Houston
"Scott H." wrote:
So I could create a global reference to the SQL wrapper class, something like
this:

Module Generic
Public MyConn as New SQLWrapper
End Module

And then use Myconn as a global variable throughout the application. Sounds
like a interesting idea. Is this generally a good practice?
--
Scott H.
"Dennis" wrote:
I have a similiar application and instantiate the Database access class in a
module so I can use it in all classes. I probalby will get "Flamed" for this
and if you don't want to do this, you can make all properties and methods
shared in the class. This way, you won't have instantiate the class as a
global.
--
Dennis in Houston
"Scott H." wrote:
I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.

Apr 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
3
by: Patrick Guio | last post by:
Hi, I have trouble to compile the following piece of code with g++3.4 but not with earlier version // Foo.h template<typename T> class Foo { public:
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
1
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of...
3
by: dischdennis | last post by:
Hello List, I would like to make a singleton class in python 2.4.3, I found this pattern in the web: class Singleton: __single = None def __init__( self ): if Singleton.__single: raise...
3
by: erictham115 | last post by:
Error C2555 c:\C++ projects\stat1\stdmatrix_adapt.h(41) : error C2555: 'std_tools::Matrix_adapter<T>::at': overriding virtual function return type differs and is not covariant from...
12
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is...
8
by: Ole Nielsby | last post by:
I want to create (with new) and delete a forward declared class. (I'll call them Zorgs here - the real-life Zorks are platform-dependent objects (mutexes, timestamps etc.) used by a...
4
by: Devon Null | last post by:
I have been exploring the concept of abstract classes and I was curious - If I do not define a base class as abstract, will it be instantiated (hope that is the right word) when a derived class is...
4
by: yuanhp_china | last post by:
I define a class in A.h: template <class Tclass A{ public: void get_elem( const T&) ; };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.