Differences creating tuples and collections.namedtuples
roy at panix.com
Wed Feb 20 15:09:08 CET 2013
In article <mailman.2087.1361343028.2939.python-list at python.org>,
Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Feb 20, 2013 at 2:38 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> > Liskov Substitution Principle (LSP): I met this over 15 years ago reading
> > debates among OOP enthusiasts about whether Rectangle should be a subclass
> > of Square or Square a subclass of Rectangle, and similarly, whether Ostrich
> > can be a legitimate subclass of Bird.
> > The problem I see with the LSP for modeling either abstract or concrete
> > entities is that we in fact do define subclasses by subtraction or
> > limitation, as well as by augmentation, while the LSP only allows the
> > latter.
> A plausible compromise is to demand LSP in terms of programming, but
> not necessarily functionality. So an Ostrich would have a fly() method
> that returns some kind of failure, in the same way that any instance
> of any flying-bird could have injury or exhaustion that prevents it
> from flying. It still makes sense to attempt to fly - an ostrich IS a
> bird - but it just won't succeed.
I would think Ostrich.fly() should raise NotImplementedError. Whether
this violates LSP or not, depends on how you define Bird.
Note: not all birds can fly. Calling fly() on
a flightless bird will raise NotImplementedError.
raise NotImplementedError("ostriches can't fly")
More information about the Python-list