Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-xxxfer.readnews.com!news-out.readnews.com!transit3.readnews.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Differences creating tuples and collections.namedtuples Date: Wed, 20 Feb 2013 09:09:08 -0500 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 42 Message-ID: References: <7a40a426-baa9-46f8-8f9d-59ba32b044f3@googlegroups.com> <5122c4d7$0$29982$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1361369349 1209 127.0.0.1 (20 Feb 2013 14:09:09 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 20 Feb 2013 14:09:09 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:39359 In article , Chris Angelico wrote: > On Wed, Feb 20, 2013 at 2:38 PM, Terry Reedy 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. > > ChrisA I would think Ostrich.fly() should raise NotImplementedError. Whether this violates LSP or not, depends on how you define Bird. class Bird: def fly(self): """Commence aviation. Note: not all birds can fly. Calling fly() on a flightless bird will raise NotImplementedError. """ class Ostrich(Bird): def fly(self): raise NotImplementedError("ostriches can't fly") class Sheep(Bird): def fly(self): self.plummet()