Re: Objective criticism of inheritance



On Wed, 06 Apr 2005 22:33:01 -0700, Dave Benjamin
<dave.benjamin@xxxxxxxxx> wrote:

>If we can consider "ifTrue" and friends to be equivalent to an
>if-statement in a programming language that doesn't anthropomorphize the
>boolean, can we likewise consider dispatch equivalent to switch/case and
>just get over it already? Because it seems to me that all switch/case
>needs to satisfy the critics is exhaustiveness checking, which is a
>programming language issue.

No, that's really not the issue. The issue is that a switch statement
*knows* every possible outcome and has a hard source code dependency
on each one. Whereas polymorphic dispatch knows *none* of the
possible outcomes and has no dependency of any kind on them.

To say this a different way, the outcomes of the switch statement have
to be in the same DLL as the switch statement. The outcomes of
polymorphism can be in completely different DLLs -- even DLLs that
weren't written at the time that the polymorphic DLL was built.


-----
Robert C. Martin (Uncle Bob) | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716


"The aim of science is not to open the door to infinite wisdom,
but to set a limit to infinite error."
-- Bertolt Brecht, Life of Galileo
.



Relevant Pages

  • Re: Best way to make a number of tests against an object(s attributes) with absence of switch statem
    ... What I'd like to do is loop through 'pets', ... Is the size 'small' and species not 'dog'? ... In PHP I'd use a switch statement similar to the following: ... The problem is that it would only dispatch on species, ...
    (comp.lang.python)
  • Re: switch
    ... using polymorphism." ... Imo the decision not to implement a switch statement was wise. ... have a switch statement because polymorphic dispatch is the right way ... If you see too many elifs in your code (or if you find yourself ...
    (comp.lang.python)
  • Re: switch
    ... This would be a pertinent question, ... using polymorphism." ... have a switch statement because polymorphic dispatch is the right way ...
    (comp.lang.python)