473,786 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A question of when to instantiate

Hi everyone,

I've been looking at the various ways to create a data access layer recently.
There was one thing in particular that occured to me and I was hoping to
garner some experienced insight into the matter.

Some people create a DA component that requires instantiation before use.
For example:

DataAccessCompo nent dac = new DataAccessCompo nent(connection String);
DataSet results = dac.GetLoggedIn Users();

Other people, myself included don't seem to see the point in actually going
to the trouble of instantiating an object to do this. We would actually just
use static methods:

DataSet results = DataAccessCompo nent.GetLoggedI nUsers();

At first look, the instantiation of an object to do this sort of stuff doesnt
seem at all neccessary - static methods work perfectly fine.

So I'm wondering if I have over looked some aspect of this problem.

Can anyone imagine a (common) situation in which instantiation has definite
benefits over the use of static classes?

Thanks to anyone who can offer any advice

Kindest Regards

TCE

Jul 22 '05 #1
5 1308
thechaosengine wrote:
So I'm wondering if I have over looked some aspect of this problem.
Can anyone imagine a (common) situation in which instantiation has
definite benefits over the use of static classes?


What if you want to use it twice, simultaneously, for two different
purposes, with different parameter inputs to the constructor?

If you're just building global methods that never change, then sure, it
doesn't matter...you might as well make it static, but a truly useful
"layer" should have some sort of configurability ...
Jul 22 '05 #2
Hi jabailo

Thanks for your reply!

I'm not quite sure what you mean though. Surely the sort of configurability
that you wish to achieve can be had by using overloaded static methods and
by passing well considered parameters - just as you would with an instantiated
object?

Where do you see the difference occuring?

Many thanks

tce

Jul 22 '05 #3
thechaosengine wrote:
Hi jabailo

Thanks for your reply!

I'm not quite sure what you mean though. Surely the sort of
configurability that you wish to achieve can be had by using overloaded
static methods and by passing well considered parameters - just as you
would with an instantiated object?

Where do you see the difference occuring?

Many thanks

tce


A static object would retain the parameters. It's 'static' in memory.

So, say you want to have two objects. One connected to tableA and the
other to tableB.

With a static, you would set it to A, and then overwrite that setting to B.

So it's always A or B, but not both.

With an instantiated object, you could create two independent data
objects, one set to A and the other to B.

You can then use the object that is instantiated with A, and also, the
object that is instantiated with B.
It really depends on your design. For example, if your data access
layer, has a relatively fixed set of data tables and tasks, then you
might want to go static, because you want to have some nice methods for
easily inserting records to a table.

But say you want the ability to have open several data objects, all of
which have similarities, but also have slight differences. And these
differences might be by data. So you would have a common set of
methods that do inserts, but you would have one object for full time
employees, and another for temp employees. You might even want to have
a common data object which is inherited by child classes overriding the
base insert methods.

But the key thing is what is your requirement, and your design preference.
Jul 22 '05 #4
And what if I need to access two different data sources at the same
time? If I go to copy a few million records between two databases on
different servers, the time penalty for opening a new connection for each
and every row can be staggering. Much better to open one connection to each
database and then copy.
Bob
"thechaosengine " <na> wrote in message
news:27******** *************@n ews.microsoft.c om...
Hi jabailo

Thanks for your reply!

I'm not quite sure what you mean though. Surely the sort of
configurability that you wish to achieve can be had by using overloaded
static methods and by passing well considered parameters - just as you
would with an instantiated object?

Where do you see the difference occuring?

Many thanks

tce

Jul 22 '05 #5
Thanks for your insight. My requirements have thus far been rather modest.
My data layer doesnt normally require anything more fancy than some simple
CRUD type functionality with only a single datasource.

I can certainly see now where instantiation might have its uses. I'd just
noticed that some people seem to choose a position out of habit so I was
wondering what the real issues around the subject might be

Thanks again for your thoughts

tce

Jul 22 '05 #6

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

Similar topics

5
2377
by: Glenn Serpas | last post by:
I have Class A and Class B .. Class B has a private member that is a pointer to a Class A object. private: B *mypointer ; I instantiate the A object A* myobject new = A();
4
5059
by: A. Gonzalez | last post by:
Hi everyone, Does anyone know how to instantiate, or create an XML document file (either using DOM or Readers) from an XML schema (xsd) file? I'm trying to develop an application that can handle different xml doc structures, but at the same time I need to create these documents, even if there's no content. So I was planning to drive it with schema files (xsd), but I haven't figured out from looking at the .net SOM how to create the...
1
1798
by: John | last post by:
Another Best Performances Practice Question: Here's the scenario, as some of you who viewed and responded to my earlier question already know: I have a public class (csValidation) which contains different validation functions. These functions will be called from within many different forms when a textbox is filled in by the user. I have an event in the form that checks the textbox and opens up the validation function in the csValidation...
2
2197
by: david | last post by:
Well, as a matter of fact I_HAD_MISSED a basic thing or two, anyway, although Ollie's answer makes perfectly sense when dealing with classes, it doesn't seem to me to apply as well if you have to instantiate an array of structures; consider the following useless code : using System; struct MyPointS
1
2983
by: Jason Lopez via .NET 247 | last post by:
I'm having a lot of trouble trying to instantiate a C++ classfrom a DLL in a C# application. The DLL was written in C++(Visual Studio 6.0). I have the full source code, as well as the compiled DLL. I washoping I'd be able to use it using the DllImport attribute, andcreating empty function declarations. I've done that before andit works well. The problem is that DllImport requires that allfunctions be static. This particular DLL requires...
12
2072
by: karen | last post by:
Hi all : this is going to be a long post. So i apologize in advance :) i am converting a java program in VB right now. I am a java programmer by trade. so i am no expert in this department. I have written the following three class: 1.icoCORE_test 2.icoMINDB_test
4
1356
by: Learner | last post by:
Hello, I have a basic question regarding 'New' keyword. For instance I can declare a variable as string (class) as Dim myName as String = String.Empty or Dim I as Integer But when I want declare a button we instantiate it as Dim b as Button = New Button
2
1342
by: Pyenos | last post by:
class model:pass class view: model() class controller: model() I can instantiate clsss model from inside class view but I can't instantiate class model from inside controller, due to the nature of python interpreter.
4
3663
by: Tomas | last post by:
A newbie question: How can I instantiate objects dynamically in VB.NET. E.g. I have the object 'Player' and I would like to instantiate it with the several instances (James, Gunner, etc.), without in advance knowing how many objects (employee1, employee2, etc) Dim player1 As New Persons.Players Dim player2 As New Persons.Players Dim player3 As New Persons.Players ....
15
2176
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object (a_obj) of a class type (A), then we need to define A as well, but if B has a pointer to A, then we only need to forward declare A. I was told this is because the compiler needs to see the implemenation of A when allocating memory for a_obj. ...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10108
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.