473,394 Members | 1,866 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,394 software developers and data experts.

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:

DataAccessComponent dac = new DataAccessComponent(connectionString);
DataSet results = dac.GetLoggedInUsers();

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 = DataAccessComponent.GetLoggedInUsers();

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 1286
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*********************@news.microsoft.com...
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
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
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...
1
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...
2
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...
1
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...
12
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...
4
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...
2
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...
4
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...
15
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.