Re: duck-type-checking?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Rowe

    Re: duck-type-checking?

    2008/11/12 Joe Strout <joe@strout.net >:
    >If you need to know that it walks like a duck, mates like a duck and
    >tastes like a duck when roasted, you probably want it to really /be/ a
    >duck and should go back to inheritance.
    >
    I can't agree; there are times when inheritance just won't do, for example
    when you don't have control over the object creation, because they come from
    some factory method you can't change. In that case you may need to make a
    wrapper instead of a subclass, but if you've faithfully implemented the
    interface of the original class, you should be able to use it wherever the
    original class could be used (within reason).
    And then the original class definition changes -- new members added --
    but the ones from the factory class don't change, and so are no longer
    compliant with the the factory class (which doesn't support the new
    "form_pun_relat ing_to_avoiding _a_high_hazard( )" method) . Fine. If you
    checked for all the members of the class that your code uses, it makes
    no difference. ABCs give you a way of doing this, but in their absence
    it's a long list of checks. If you /can/ use inheritance then it saves
    having to do those checks.

    --
    Tim Rowe
Working...