473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Method overloading does this look right to you?

I have the following method:

public void Execute(TCPComm and command, out string outputResponse, out
string error)
{

//snipped code
outputResponse = "some message";
error = "";
}
now I need to a new overload for this without error and output parameters:

public void Execute(TCPComm and command)
{
string param;
Execute(command , out param, out param);
}
But it doesn't feel right declaring new string variable just for that.. Is
there a way to pass in "null" references. String.Empty doesn't work. Or is
this the best way to handle something like this.

Thanks!
Nov 17 '05 #1
4 1306
First of all, it looks like you are passing in the same object for both
parameters. That means whichever one's value you set last, that will be what
is in that variable. So that doesn't really help you.

I would in this case have Execute return an object (so you define a new
class for this), with properties OutputResponse and ErrorMessage or
something like that. It would then need just the 'command', to tell it what
to do, so you would only have one version of the method. You can always just
ignore the return value of Execute if you don't care about the output or
error messages. And, it means that if in the future there are is any other
information for Execute to return, you can just add it to that return class.

"Lenn" <Le**@discussio ns.microsoft.co m> wrote in message
news:79******** *************** ***********@mic rosoft.com...
I have the following method:

public void Execute(TCPComm and command, out string outputResponse, out
string error)
{

//snipped code
outputResponse = "some message";
error = "";
}
now I need to a new overload for this without error and output parameters:

public void Execute(TCPComm and command)
{
string param;
Execute(command , out param, out param);
}
But it doesn't feel right declaring new string variable just for that.. Is
there a way to pass in "null" references. String.Empty doesn't work. Or is
this the best way to handle something like this.

Thanks!

Nov 17 '05 #2
Marina <so*****@nospam .com> wrote:
First of all, it looks like you are passing in the same object for both
parameters. That means whichever one's value you set last, that will be what
is in that variable. So that doesn't really help you.
It does, because the point is that the method being called really
doesn't care about the value put into the response/error - it's not
doing anything with it afterwards.
I would in this case have Execute return an object (so you define a new
class for this), with properties OutputResponse and ErrorMessage or
something like that. It would then need just the 'command', to tell it what
to do, so you would only have one version of the method. You can always just
ignore the return value of Execute if you don't care about the output or
error messages. And, it means that if in the future there are is any other
information for Execute to return, you can just add it to that return class.


Yes, that sounds like a better idea to me - or perhaps just returning a
string and throwing an exception on error, unless getting an error
*really* isn't fatal as far as the method itself is concerned.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
> First of all, it looks like you are passing in the same object for both
parameters. That means whichever one's value you set last, that will be what
is in that variable. So that doesn't really help you.
Let me try to explain, there are some clients that care about Error and
response and some clients that don't. If a client calls Execute overload
without error and response, obviously it doesn't care. So it doesn't matter
what the value is for those params since those params never get to the client.

I would in this case have Execute return an object (so you define a new
class for this), with properties OutputResponse and ErrorMessage or
something like that. It would then need just the 'command', to tell it what
to do, so you would only have one version of the method. You can always just
ignore the return value of Execute if you don't care about the output or
error messages. And, it means that if in the future there are is any other
information for Execute to return, you can just add it to that return class.


I already have a client app that use this class. It relies on errors and
response output params. However I need to write a new client and requirements
dictate that this client doesn't care for any errors or output, because none
will be returned. So I want to write new overload without error and response
params, but I don't want to break existing working client either. I could
just have new client pass in those params and ignore them, but overload
seemed like the most logical way.
Nov 17 '05 #4
Ok, I just sort of said that in case that overload may do something with
those parameters. I guess not.

In any case, declaring a new string variable, just to have something to pass
in is not a big deal.

"Lenn" <Le**@discussio ns.microsoft.co m> wrote in message
news:C9******** *************** ***********@mic rosoft.com...
First of all, it looks like you are passing in the same object for both
parameters. That means whichever one's value you set last, that will be
what
is in that variable. So that doesn't really help you.


Let me try to explain, there are some clients that care about Error and
response and some clients that don't. If a client calls Execute overload
without error and response, obviously it doesn't care. So it doesn't
matter
what the value is for those params since those params never get to the
client.

I would in this case have Execute return an object (so you define a new
class for this), with properties OutputResponse and ErrorMessage or
something like that. It would then need just the 'command', to tell it
what
to do, so you would only have one version of the method. You can always
just
ignore the return value of Execute if you don't care about the output or
error messages. And, it means that if in the future there are is any
other
information for Execute to return, you can just add it to that return
class.


I already have a client app that use this class. It relies on errors and
response output params. However I need to write a new client and
requirements
dictate that this client doesn't care for any errors or output, because
none
will be returned. So I want to write new overload without error and
response
params, but I don't want to break existing working client either. I could
just have new client pass in those params and ignore them, but overload
seemed like the most logical way.

Nov 17 '05 #5

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

Similar topics

17
4701
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 manual mentions "overloading" (http://no.php.net/manual/en/language.oop5.overloading.php), but it isn't really overloading at all... Not in the sense...
5
5219
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that discussions of new and delete is a pretty damn involved process but I'll try to stick to the main information I'm looking for currently. I've searched...
2
3006
by: Kamran | last post by:
Hi I have very little experience of C++, nevertheless I have been asked to write a gui using QT/QWT. I know that I should direct the question to the relevant mailing list and I have done that but I think my problem has to do with my lack of understandign of some issues in C++. There is a class in QWT called QwtPicker which allows one to...
18
4712
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
4
1304
by: Panos Laganakos | last post by:
I want a class method to take action depending on the type of the arguement passed to it. ie: getBook(id) # get the book by ID getBook(name) # get the book by name .... Other languages use the term function/method overloading to cope with this. And when I googled about it seems that GvR is testing it for 3.0
19
2418
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
11
28108
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
5
1313
by: Andreas Schmitt | last post by:
I have a problem here. I've read a book about C# already and got the basics of how the language handles polymorphism I think but I ran into a problem here that I simply never even thought of as a problem coming from C++: I wrote some code similar to this: abtract public class Base { }
10
3472
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
7457
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...
0
7391
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...
0
7651
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. ...
0
7802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7746
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...
0
5962
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
5320
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...
1
1869
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
0
693
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.