CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Ranjan Sakalley


Multiple overloads with distinguishing parameter as object is dangerous

 From John Papa's post to Jackie Goldstien's that quoted Pablo Castro[MS], got these words that were somewhere in my mind but never expressed. Thanks all.

In general, having multiple overloads where the distinguishing parameter type is “object” in one of them is a dangerous thing to do.

 


Published Apr 06 2005, 11:37 PM by rsakalley
Filed under:

Comments

John Papa said:

Got to love blog chains! ;-)

Yeah, I found that interesting as well.
# April 7, 2005 4:50 AM

Raymond Lewallen said:

It can be dangerous, but usually isn't an issue. The compiler is pretty good at matching up strongly-typed parameters with whatever data types you are passing in, therefore almost always choosing the right overloaded method, which is not going to the overloaded method that takes an object type. I actually tested this type of thing out a while back. My conclusion was that as long as you provide the overloaded method with the matching datatypes, the overloaded method with object datatypes won't be used, and it won't be an issue. Just as soon as I post this somebody will certainly come back with some code to prove me wrong :) but try it out for yourselves.

Public Sub Bar(ByVal name As String, ByVal age As Int32)

Public Sub Bar(ByVal name As Object, ByVal age As Int32)

Public Sub Bar(ByVal name As String, ByVal age As Object)

Public Sub Bar(ByVal name As Object, ByVal age As Object)

Public Sub TestTheBar()
Me.Bar("Raymond Lewallen",29)
End Sub


Its going to choose Bar(string,int32) in this case, and in pretty much all cases I tested when providing the correct overloaded methods.

I think the SqlParameter.Add() was an exception in the fact that the compiler would chose the wrong overload.
# April 7, 2005 5:39 AM

Brendan Tompkins said:

I read somewhere, and I really have to go back and find the source, that multiple overloads in and of themselves are usually a sign of a poorly designed object model.

I've found this to be true in a lot of situations. It's just one of those things I keep in mind when I find myself with more than 2 or 3 overloads.
# April 7, 2005 7:02 AM

Joshua Flanagan said:

The difference between your example, and SqlParameterCollection.Add(), is that your overloads that take 2 parameters have the same meaning. In all of your overloads, the 2nd parameter sets the age. In the SqlParameterCollection, the overload that takes a SqlDbType has a different meaning than the overload that takes an object.
That is where it is dangerous, since you don't know which implementation it will choose.
When you say:
SqlParameterCollection.Add("param" 0)
- the compiler could interpret that as "create a parameter with this data type, without setting the value", or "create a parameter with this value".
Sure, if both overloads were performing the same functionality (as in your example), it would not be a problem.
# April 7, 2005 7:09 AM

Raymond Lewallen said:

Josh, I agree. I was just pointing out that I believe SqlParameter.Add is the exception to the case, and that under most normally designed overloaded methods, worrying about the object parameter overload wouldn't be an issue.
# April 7, 2005 7:40 AM

John Papa said:

I agree that overloaded methods should be used in moderation just like optional parameters should be used in moderation. I just ran through some code last week where I saw 12 overloaded methods to save data! (It is now down to 3.) Overall I love overloading and actually prefer it to optional parms, but I have no reasoning for that other than personal preference.
# April 7, 2005 7:56 AM

NeVaL said:

http://www.l-kone.beibi.info ^^^ http://www.l-koodi.beibi.info ^^^ http://www.lade-lefdal-klipp.biseksuell.info ^^^ http://www.gallerier-stripping-handjager.biseksuell.info ^^^ http://www.lade-lefdal-klipp.erotiska.info ^^^ http://www.gallerier-stripping-handjager.erotiska.info ^^^ http://www.ralf-schumacher.fitta69.info ^^^ http://www.gratis-anal-aldre.fitta69.info ^^^ http://www.spermakaskader-erotiskanoveller.fotsex.info ^^^ http://www.bild-homosexuell-vat.fotsex.info ^^^ http://www.leike-munaa-pillu.isomuna.info ^^^ http://www.penis-gay-ilmasto.isomuna.info ^^^ http://www.pornqueens-orgasmi-peraaukon.laukeaminen.info ^^^ http://www.mieluisa-matala.laukeaminen.info ^^^ http://www.smisk-fitta-film.rype.info ^^^ http://www.nakne-russejenter-bilde.rype.info ^^^ http://www.fisse-bolle-gratis.sadsprut.info ^^^ http://www.foto-handjager-sjuskete.sadsprut.info ^^^ http://www.bukkaketorrent-naida-leike.tytsy.info ^^^ http://www.tytsyt-pano-mpeg.tytsy.info ^^^ http://www.ass-fingering-freesex.18analsex.com ^^^ http://www.anal-lovers-film.18analsex.com ^^^ http://www.donna-brasiliana-nuda.pazzesesso.com ^^^ http://www.mpg-cumshot-clit.pazzesesso.com ^^^ http://www.galleria-perreo-video.figanere.com ^^^ http://www.filmati-trigliceridi-bassi.figanere.com ^^^ http://www.virgilio-meteo-sesso.inculatexxx.com ^^^ http://www.mpgs-spagnoletta-seno.inculatexxx.com ^^^ http://www.ice-clit-download.prostitutaculo.com ^^^ http://www.mano-culo-clip.prostitutaculo.com ^^^ http://www.jpg-piede-cavo.lesbicastrip.com ^^^ http://www.mpgs-folliero-emanuela.lesbicastrip.com ^^^ http://www.clips-soy-putita.007sexogratis.com ^^^ http://www.clip-vecinas-cachondas.007sexogratis.com ^^^ http://www.uniformes-de-hosteleria.3sexogratis.com ^^^ http://www.masajes-desnudos-sexo.3sexogratis.com ^^^ http://www.clip-chica-culiando.analsexogratis.com ^^^ http://www.espaniol-potorros.analsexogratis.com ^^^ http://www.galeria-pendeja-puta.cam-sexo-gratis.com ^^^ http://www.chat-lesbi-videos.cam-sexo-gratis.com ^^^

# December 28, 2006 5:54 AM

Smułko said:

http://www.quad.org.es/gradevole-fighetta-sex.html

http://145154260.luce.nom.es/

http://www.quad.org.es/milano-tango.html

http://www.bisg.org.es/invisible-bionde-doppio-penetrazione.html

http://www.iolao.nom.es/152655692/

http://145233776.luce.nom.es/

http://treviso-ufficio.dfms.org.es/

http://www.aegon.nom.es/erotici-annunci-di-sex.html

http://www.azvu.nom.es/consulting-management.html

http://www.neila.org.es/147636276/

http://www.dmdaa.org.es/piano-cottura-gas.html

http://www.bomet.nom.es/pochi-soldo.html

http://www.ntex.nom.es/inchiodare-cowgirl.html

http://144935480.bibbo.com.es/

http://mare-neve-vacanza.dfms.org.es/

http://www.fapas.org.es/storia-di-fonderia.html

http://145183336.luce.nom.es/

http://www.dmdaa.org.es/testo-unico-finanza.html

http://www.dindl.nom.es/150617508/

http://www.ducis.nom.es/monitor-lcd-21.html

http://www.vtya.com.es/43xghkgwgx4.html

http://www.pipes.org.es/ecdl-computer-corso.html

http://riservato-cowgirl-strip.cranv.com.es/http://milano-stalingrado.jht3k7963m7.info/

http://nice-infermiera-prostituta.t315o15wuo0.info/

http://troie-pelose.5rbqrq3fqgi.info/

http://invio-sms-registrazione.79pkaqzrpg2.info/

http://digital-camera-software.kjba0i22p1i.info/

http://ridicolo-lesbiche-schizzate-di-figa.nmlnrjuk87j.info/

http://luna-hotel-venice.jht3k7963m7.info/

http://allievo-asiatiche-amore.cn3u6te3gqn.info/

http://gas-blue-jeans.x7lo2fujz5l.info/

http://grill-barbecue.79pkaqzrpg2.info/

http://www.2qhtadoaxcg.info/tariffa-telefono/

http://amore-incontro-bergamo.dhffimsbmup.info/

http://www.2qhtadoaxcg.info/solo-volo-creta.html

http://panca-inversione.o8nr6j39nzr.info/

http://fighe-mature.nmlnrjuk87j.info/

http://d2sbbvladf.u3yomyk50cp.info/

http://affitto-vacanza-canarie.nupsvtr1xzi.info/

http://prenotazioni-online.t315o15wuo0.info/

# January 24, 2007 1:18 AM

volf said:

http://www.archives.gszgacsdgif.info/137103700.html -Y-

http://www.sexoweb.ahost.lomza.pl/p1mvd43q3y/ -Y-

http://www.archives.gszgacsdgif.info/137116432.html -Y-

http://mujers-elegantes.ahost.lomza.pl/ -Y-

http://www.blog.ovoc.karpacz.pl/5qxyrbp.html -Y-

http://www.sgxr7drif1e.info/maduras-xxl.html -Y-

http://videos-masturbacion.gszgacsdgif.info/ -Y-

http://www.archivos.ovoc.karpacz.pl/136903744/ -Y-

http://www.archivos.epqt9tu0hfa.info/ver-fotos-terrorificas.html -Y-

http://nalgas-pic-vid.ovoc.karpacz.pl/ -Y-

http://www.blog.sgxr7drif1e.info/4rf8ftvyvgs/ -Y-

http://www.buscador.dot.mielec.pl/137269636.html -Y-

http://gitanas-picantes.dot.mielec.pl/ -Y-

http://www.sexoweb.ahost.lomza.pl/8c2aplwqqs/ -Y-

http://nudes-galerias-fuck.gszgacsdgif.info/ -Y-

http://mugeres-buscando-xeso.dot.mielec.pl/ -Y-

http://voyerismo-pics.v1jsnlqd6fl.info/ -Y-

http://www.archivos.epqt9tu0hfa.info/bukkake-gallery.html -Y-

http://el-jamon-chicas.ahost.lomza.pl/ -Y-

http://www.paginas.dot.mielec.pl/putas-culonas-fuck.html -Y-

http://chicas-navidad.ahost.lomza.pl/ -Y-

http://www.port01.ovoc.karpacz.pl/137611772/ -Y-

http://fotos-de-minifaldas.ovoc.karpacz.pl/ -Y-

http://www.epqt9tu0hfa.info/edecanes-ucranianas.html -Y-

http://www.port01.ovoc.karpacz.pl/137612288/ -Y-

http://www.espana.dot.mielec.pl/nenas-sensuales-sex/ -Y-

http://madura-chupandola.dot.mielec.pl/ -Y-

http://www.sgxr7drif1e.info/mujeres-italianas-culonas.html -Y-

http://www.port01.ovoc.karpacz.pl/137485496/ -Y-

http://www.archivos.ovoc.karpacz.pl/mujeres-importantes.html -Y-

http://fotos-contacto.gszgacsdgif.info/ -Y-

http://pornografia-ilegal.dot.mielec.pl/ -Y-

http://pajas-xxx.ovoc.karpacz.pl/ -Y-

http://abuela-mpg-nude.ahost.lomza.pl/ -Y-

# February 5, 2007 4:52 PM

Bożo said:

http://hzbpe8rodyv.peri.waw.pl/

http://www.solidarnosc.opole.pl/assurdo-giovane-merda/

http://www.lechmet.mielec.pl/foto-hard-gratuite.html

http://www.inshallah.it/negre-puttane-gratis.html

http://riservato-cowgirl.wetfingeroperation.it/

http://www.vivanuoto.it/annunci-foto-coppie.html

http://www.inshallah.it/136495672/

http://casalinghe-sexy-vicenza.rckik.slupsk.pl/

http://www.pro4you.it/beautiful-ragazze-sex.html

http://sex-gif.guelfi-ghibellini.it/

http://ragazze-pelose.sacrum.waw.pl/

http://www.pro4you.it/sexe-anal/

http://spiate-net.riosoglia.it/

http://farcical-segretaria-strip.sacrum.waw.pl/

http://sesso-puttanone.rckik.slupsk.pl/

http://a66525e9kl.inshallah.it/

http://sex-grassone.pro4you.it/

http://fresco-ragazze-inculate.riosoglia.it/

http://www.vivanuoto.it/crave-fighette-dildo.html

http://www.lechmet.mielec.pl/137503708/

http://sexy-minorenni.wetfingeroperation.it/ http://www.instar.limanowa.pl/users/viodonnemature/congenial-ragazze-gruppo/

http://www.instar.limanowa.pl/users/seonneincinta/t6bs4l7.html

http://www.instar.limanowa.pl/users/raciottenni/amatoriali-dildo-in-anticamera.html

http://www.instar.limanowa.pl/users/gamatoriali/145195516/

http://www.instar.limanowa.pl/users/viodonnemature/fuoriclasse-corto/

http://www.instar.limanowa.pl/users/dubrins/comfortable-agente-di-polizia-orale-fotti.html

http://www.instar.limanowa.pl/users/gamatoriali/145197568/

http://www.instar.limanowa.pl/users/ceestiti/7julthmxvq.html

http://www.instar.limanowa.pl/users/matiche/s1qoa2q.html

http://www.instar.limanowa.pl/users/culosi/145012292.html

http://www.instar.limanowa.pl/users/splispogliatoi/faint-cameriera-ubriache/

http://www.instar.limanowa.pl/users/seonneincinta/5tanjxa.html

http://www.instar.limanowa.pl/users/dotande/offshore-account/

http://www.instar.limanowa.pl/users/viodonnemature/e6hnypy4d4.html

http://www.instar.limanowa.pl/users/mai/verona-alloggio.html

http://www.instar.limanowa.pl/users/dubrins/crave-cowgirl-urinate.html

http://www.instar.limanowa.pl/users/viodonnemature/mvejho8fzq.html

http://www.instar.limanowa.pl/users/40sispogliano/28ckeokn.html

http://www.instar.limanowa.pl/users/viinis/aboutgay-incontri.html

http://www.instar.limanowa.pl/users/dubrins/modem-driver.html

# February 22, 2007 1:05 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!