Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.05; 'attributes': 0.07; 'cc:addr:python-list': 0.10; 'def': 0.14; 'thu,': 0.15; 'copied,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'non-trivial': 0.16; 'opened,': 0.16; 'subject:OOP': 0.16; 'two,': 0.16; 'wrote:': 0.16; '(or': 0.21; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'doc': 0.22; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'raise': 0.24; 'sort': 0.25; 'define': 0.27; 'message-id:@mail.gmail.com': 0.28; 'interface': 0.29; 'arguments,': 0.29; 'extending': 0.29; 'oop': 0.29; 'print': 0.31; 'up.': 0.32; 'class': 0.33; 'received:google.com': 0.34; 'cases': 0.36; 'should': 0.37; 'subject:: ': 0.37; 'files': 0.38; 'pm,': 0.39; 'share': 0.60; 'simple': 0.61; 'chrisa': 0.84; 'forced': 0.84; 'subject:Classic': 0.84; 'to:none': 0.90; 'boxes,': 0.91; 'railway': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=u1Z8LcgMGCVsZ+5gwcLeHOWE5ErXPIhg4aI+4Bi8qp0=; b=1Fi+Gkkkkf5bmBv3cVoZjvxbtI962wrCTPl6AAblFK5x8hzGEuO6AXEP+Py5DLAYDF b2SHvZCS6U1uRgK4D52Yt474HAOicG27xd6NBLqF6c3p6goRDsEfUvseODuzsTF0AlXU EcJRPDBNqQ/13lxF8XWarS36/Rqkv7FBAVFWRKCgn66Hnc1fO4oOFtpYvKPmDca7zLQU rp9lnerNCF8acuGvUJJP5Uk4D8aK2jFL5CkuGJUfsLC2jf6ZUUe7Y5kvnNtbNE1LL+Ok 809qwCCjBbmaLV1UT5IRTnCjzZum2UEE/Gm5JgG3XoJ3QAJu6HPrc5GBKOpQsJM1Hc24 CzKg== MIME-Version: 1.0 X-Received: by 10.50.143.104 with SMTP id sd8mr41314854igb.14.1434627808694; Thu, 18 Jun 2015 04:43:28 -0700 (PDT) In-Reply-To: References: <23b2fae3-91d5-486b-9898-78b34bee486f@googlegroups.com> Date: Thu, 18 Jun 2015 21:43:28 +1000 Subject: Re: Classic OOP in Python From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434627811 news.xs4all.nl 2946 [2001:888:2000:d::a6]:42213 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92822 On Thu, Jun 18, 2015 at 9:03 PM, Fabien wrote: > Would you consider the following kind of program "unpythonic"? > > class MovingObject(object): > """Great doc about what a moving object is""" > > def move(self): > """Great doc about move""" > raise NotImplementedError() > > class Dog(MovingObject): > def move(self): > print "Dog is moving" > > class Car(MovingObject): > def move(self): > print "Car is moving" > > (Disclaimer: I learned OOP with Java) Now try extending the concept to two, three, or four such interfaces. Files can be moved, opened, copied, and unlinked. Should they share any sort of interface with dogs, boxes, handwriting, and railway carriages? It's much better to simply define the attributes of each object separately; most non-trivial cases don't involve simple methods with no additional arguments, and the chances of an incompatibility (or worse, a forced compatibility) go up. ChrisA