Personally I would fall back to using functional concepts in this case (currying)....
But of the two options I would say that you would generally want Add(int) as opposed to redefining the behavior of Add(int, int) and special casing it ... This is obviously decided though by whether you are actually attempting to extend the behavior or whether you really need to polymorphically change the behavior (if you are changing the behavior I think you should really be asking yourself WHY you are needing to do this as it is breaking LSP (perhaps you should be introducing a new strategy object?)) ... Cheers, Greg On Nov 20, 2007 10:36 AM, Abhijit Gadkari <[EMAIL PROTECTED]> wrote: > I was doing some code review. I saw something interesting ā Liskov > implementation. [for more info, check out > http://en.wikipedia.org/wiki/Liskov_substitution_principle] > > Here is the sample implementation of the same. > > namespace ToTest > { > class Liskov > { > public Liskov() > { > //do nothing > } > > public virtual int Add(int one,int two) > { > return one + two; > } > } > > class DerievedLiskov :Liskov > { > public DerievedLiskov() > { > //do nothing > } > > /// <summary> > /// <para>to add the number to itself.For Example - Add(4,0) will > result 8</para> > /// </summary> > /// <param name="one"></param> > /// <param name="two"></param> > /// <returns></returns> > public override int Add(int one, int two) > { > if (two == 0) > { > return one + one; > } > else > { > return base.Add(one, two); > } > } > > public int Add(int one) > { > return one + one; > } > } > } > > Now, I know there is no validation here. But the point is about > substitution principle. Here we have Add method in the base class. An > override in derived class will substitute it. > > SO if we want to change the behavior of Add method such that it will > accept only one integer and will return the result as int added to itself > [i.e. 3+3=6],we have two options as coded in the DerievedLiskov. Which one > is beter from oo design point? > > Thanks. > > Abhi > > =================================== > This list is hosted by DevelopMentor(R) http://www.develop.com > > View archives and manage your subscription(s) at http://discuss.develop.com > -- Studying for the Turing test =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com