Dean Wampler wrote:
> On Wed, Nov 5, 2008 at 1:51 PM, Pat Maddox <pergesu / gmail.com> wrote:
>>> Rectangle always substitutable for a Square? If you have mutable
>>>
>>> dean
>>
>> I think the answer is "it depends."  I would argue that the specs you
>> gave are great for verifying that the implementation of Square works,
>> but not so great at defining the contract.  The contract for calculating
>> area may be a bit fuzzy to spec out, but I think you can be happy by
>> saying that the area should be greater than one of the sides.  Now a
>> Rectangle is substitutable for a Square.
>>
>> Pat
> 
> Right. That's why I said "clients of Square have a contract". It's an
> interesting feature of Liskov substitution that it doesn't just
> involve the types in isolation; it also involves users of the types.
> There are certainly situations where the extra constraint on
> "real-world" squares isn't an issue.

An interesting approach that I recently read about was that the "is-a" 
relationship should really be thought of as a "behaves-as-a" 
relationship where OO is concerned. In this case a square really doesn't 
behave like a rectangle. In this sense, a square is not a rectangle.
-- 
Posted via http://www.ruby-forum.com/.