From: Barry K. <bk...@in...> - 2002-11-20 15:49:13
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> Tim Mackinnon wrote:<br> <blockquote type=3D"cite" cite=3D"mid...@po..."> <title></title> <meta http-equiv=3D"Content-Type" content=3D"text/html; "> <meta content=3D"MSHTML 5.50.4919.2200" name=3D"GENERATOR"> <div><span class=3D"153461600-20112002"><font face=3D"Arial" color=3D"#0000ff" size=3D"2">I have been a silent lurker on this on= e - but there is a code smell here... using overloading of methods in this w= ay is a bad sign (it may ultimately be legitamate but there is a smell I h= ave encounterered in other java code).</font></span></div> <div><span class=3D"153461600-20112002"></span>=A0</div> <div><span class=3D"153461600-20112002"><font face=3D"Arial" color=3D"#0000ff" size=3D"2">If you want to avoid an if statment bu= t are relying on overloading to get this - </font></span></div> </blockquote> <br> The overloading has nothing to do with the avoidance of if-statements= , as I think I mentioned earlier.<br> <br> <blockquote type=3D"cite" cite=3D"mid...@po..."> <div><span class=3D"153461600-20112002"><font face=3D"Arial" color=3D"#0000ff" size=3D"2">there is an issue. </font></span><span class=3D"153461600-20112002"><font face=3D"Arial" color=3D"#0000ff" = size=3D"2">From a quick glance, this looks like a double dispatch pattern - the obje= ct you are passing in is a visitor, different objects call back using the d= ifferent method signatures -</font></span></div> </blockquote> <br> No, this is not a visitor. It is simply a multi-key lookup, in which = the clients know the keys, but are closed to the key values.<br> <br> <blockquote type=3D"cite" cite=3D"mid...@po..."> <div><span class=3D"153461600-20112002"><font face=3D"Arial" color=3D"#0000ff" size=3D"2"> this isn't polymorphic at all - you d= on't really gain anything from giving the same method name to=A0the two methods = as they are just differnt =A0(they have different paramaters anyway) - why n= ot be clearer and say getShorQuatity.... and getPositionQuatity (eg. diffe= rent names).</font></span></div> <div><span class=3D"153461600-20112002"></span>=A0</div> <div><span class=3D"153461600-20112002"><font face=3D"Arial" color=3D"#0000ff" size=3D"2">If you want polymorphism - getQuatity = should have the same parameter with some other object that has the details requi= red. This is often the smell - you are missing some other object (which i= s the single paramater)- your tests may be telling you this???</font></spa= n></div> </blockquote> <br> I've made no claim of polymorphism (If I did it was in error). What I= did/do claim was the desire to eliminate the client from having to know the = key values, and invoke different methods depending on those values. <br> <br> The overloading is completely orthoginal to the issue of the client n= ot requiring ifs, and support for overloading in mocks. And of course no client ca= n act in a polymorphic manner with regard to the two overloaded methods as = they have different parameter types (maybe this is what you pointing out).= In fact, the same client does not use both methods. Yes, I could name th= e two methods differently (in the spirit of Effiel), but again that is a di= fferent topic from the support of overloaded methods in mocks.<br> =20 <blockquote type=3D"cite" cite=3D"mid...@po..."><sp= an class=3D"153461600-20112002"></span><font face=3D"Tahoma"></font> <div><font face=3D"Tahoma"><br> <font size=3D"2"><span class=3D"153461600-20112002"><font face=3D"A= rial" color=3D"#0000ff">If you were overloading with the same number of pa= rameters - is there something common in those parameters (ie some interface) = - if so the interaced parameters should be used and the mock would be si= mple.</font></span></font></font></div> </blockquote> <br> No. What is common is the intention: "get the position quantity".<br> <br> Thanks for the feedback Tim.<br> <blockquote type=3D"cite" cite=3D"mid...@po..."> <div><font face=3D"Tahoma"><font face=3D"Arial" color=3D"#0000ff" s= ize=3D"2"><span class=3D"153461600-20112002"></span></font></font></div> </blockquote> <br> <br> </body> </html> |