473,406 Members | 2,281 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.

Overloading alternatives?


Hi,

Sorry I am new to object oriented.

I was trying to build a class from which I could retrieve DataSets, DataReader, execute SQL, etc. Some kind of SQL class. I thought that creating methods such as "RunSql" and "RunProc" would be a good idea, but then realized that it is not possible to create method overloading as follows:

public DataSet RunSql(string sSql, string sTableName)
public DataReader RunSql(string sSql)
public void RunSql(string sSql)

The above won't work, since the first two methods have the same signature. Is there a nice way of keeping the method name the same (RunSql) but return a different object? I was thinking about "Object" as return parameter, but won't there be a performance problem since casting is involved? Or should I just create different method with "getDataSet(...)", "getDataReader(...)", etc.?

Thanks
Mike

Nov 15 '05 #1
5 1430
Mike <no****@hotmail.com> wrote:
Sorry I am new to object oriented.

I was trying to build a class from which I could retrieve DataSets,
DataReader, execute SQL, etc. Some kind of SQL class. I thought that
creating methods such as "RunSql" and "RunProc" would be a good idea,
but then realized that it is not possible to create method overloading
as follows:

public DataSet RunSql(string sSql, string sTableName)
public DataReader RunSql(string sSql)
public void RunSql(string sSql)

The above won't work, since the first two methods have the same
signature. Is there a nice way of keeping the method name the same
(RunSql) but return a different object? I was thinking about "Object"
as return parameter, but won't there be a performance problem since
casting is involved? Or should I just create different method with
"getDataSet(...)", "getDataReader(...)", etc.?


Well, what's the difference between void RunSql and DataReader RunSql?
Where would you use one, and where would you use the other? An
appropriate name should be given to distinguish them for the developer
as well as the compiler.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

Jon,

I would use "void RunSql" to run a sql statement for which I don't need a
return value. The other "DataReader RunSql" would be used in situations
where I need a DataReader back. Do you think I should use the following
instead:

public void RunSql(string statement)
public DataReader ExecReaderSql(string statement)
public DataReader ExecReaderProc(string procname)
public DataSet ExecSetSql(string statement)
public DataSet ExecSetProc(string procname)

Thanks.

--
Michael

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <no****@hotmail.com> wrote:
Sorry I am new to object oriented.

I was trying to build a class from which I could retrieve DataSets,
DataReader, execute SQL, etc. Some kind of SQL class. I thought that
creating methods such as "RunSql" and "RunProc" would be a good idea,
but then realized that it is not possible to create method overloading
as follows:

public DataSet RunSql(string sSql, string sTableName)
public DataReader RunSql(string sSql)
public void RunSql(string sSql)

The above won't work, since the first two methods have the same
signature. Is there a nice way of keeping the method name the same
(RunSql) but return a different object? I was thinking about "Object"
as return parameter, but won't there be a performance problem since
casting is involved? Or should I just create different method with
"getDataSet(...)", "getDataReader(...)", etc.?


Well, what's the difference between void RunSql and DataReader RunSql?
Where would you use one, and where would you use the other? An
appropriate name should be given to distinguish them for the developer
as well as the compiler.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Mike <no****@hotmail.com> wrote:
I would use "void RunSql" to run a sql statement for which I don't
need a return value. The other "DataReader RunSql" would be used in
situations where I need a DataReader back. Do you think I should use
the following instead:

public void RunSql(string statement)
public DataReader ExecReaderSql(string statement)
public DataReader ExecReaderProc(string procname)
public DataSet ExecSetSql(string statement)
public DataSet ExecSetProc(string procname)


That would seem reasonable, yes. You might want to look at IDbCommand,
and its ExecuteNonQuery, ExecuteReader etc methods for more
inspiration, too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

Thanks a lot.

--
Michael
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mike <no****@hotmail.com> wrote:
I would use "void RunSql" to run a sql statement for which I don't
need a return value. The other "DataReader RunSql" would be used in
situations where I need a DataReader back. Do you think I should use
the following instead:

public void RunSql(string statement)
public DataReader ExecReaderSql(string statement)
public DataReader ExecReaderProc(string procname)
public DataSet ExecSetSql(string statement)
public DataSet ExecSetProc(string procname)


That would seem reasonable, yes. You might want to look at IDbCommand,
and its ExecuteNonQuery, ExecuteReader etc methods for more
inspiration, too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5

Hi Mike,

I am glad your problem resolved.

If you have further concern , please feel free to post, we will help you.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6

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

Similar topics

17
by: Terje Slettebų | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
33
by: Jacek Generowicz | last post by:
I would like to write a metaclass which would allow me to overload names in the definition of its instances, like this class Foo(object): __metaclass__ = OverloadingClass att = 1 att = 3
13
by: denis wendum | last post by:
In a nutshell: What is the equivalent of __radd__ (wich overloads the right hand side of +) when overloading the comparison operators <,>,== and so on. My first guess __rlt__ for overloading the...
12
by: Joe | last post by:
Hi, Can I pass a "generic" class pointer as an argument to a function? For instance say classA and B are both derived from Z. { int iType =1;
10
by: Ramprasad A Padmanabhan | last post by:
Hi All, I am a c/perl programmer trying my hand at C++. In my code below I have an array class where I am trying to add two arrays using "+" . I am not sure why I get a '0' always for the first...
39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
31
by: | last post by:
Hi, Why can I not overload on just the return type? Say for example. public int blah(int x) { }
5
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary,...
4
by: gamename | last post by:
Hi, I'm a recent convert from TCL. One of the more powerful aspects of TCL is the ability to rename a function at will (generally for testing purposes). Example from the tcl doc: rename...
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: 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
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...
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
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...
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.