On Wed, Aug 4, 2010 at 4:50 PM, silky <[email protected]> wrote:
>> Wouldn't increasing access technically just be adding a member to the
>> subclass?  A member that, publicly anyway, the superclass didn't have.
>>
>> What happens internally is pretty irrelevant.
>>
>> In my book, decreasing is always bad.  I've seen it happen in some
>> Microsoft classes.  It was really annoying.  I can't imagine when this
>> would be a good idea.
>
> Arjang kind of misrepresented what LSP is about. Not only is it not a
> "rule", and it's a principal, as the "P" indicates, it's not about
> restricting 'access' but restricting functionality.
>
> That is to say, if you were to follow LSP, you must have Rectangle
> inherit from Square, and not Square extending Rectangle (and having
> limiting conditions).
>
> --
> silky

But that is an OOD issue in general:

You start with Object (universal object)
become more explicit with Shape
then again with Quadrilateral
then with Rectangle
the with Square

and by this stage you have various properties like Perimeter, Sides,
and Length all dependent on Width.

Or

You start with Object (now seen as an item with all parameters fixed)
become less explicit with Square
then less with Rectangle
then less with Quadrilateral
then less with Shape

but by this stage you have Sides, Length and Width properties that
don't make any sense.

However, although the former is better aligned with the intention of
inheritance, the latter may sometimes be better to implement,
especially if you only have a chain of two of the examples I gave, or
if you don't use inheritance but aggregation, i.e. the more explicit
object is only used internally to hold the properties that still make
sense.

-- 
Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)

Reply via email to