Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.048 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'subject:Python': 0.05; 'classes.': 0.07; 'texas': 0.07; 'executes': 0.09; 'aug': 0.13; '(the': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inheritance': 0.16; 'subject: \n ': 0.16; 'subject:object': 0.16; 'subject:oriented': 0.16; 'subject:programming': 0.16; 'wrote:': 0.17; 'any,': 0.17; 'thu,': 0.17; 'all,': 0.21; 'received:209.85.214.174': 0.21; 'body,': 0.22; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; '(as': 0.27; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; "d'aprano": 0.29; 'represented': 0.29; 'steven': 0.29; 'wind': 0.29; 'class': 0.29; 'knows': 0.30; 'could': 0.32; 'up!': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'generic': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'but': 0.36; "i'll": 0.36; 'subject:with': 0.36; 'why': 0.37; 'systems,': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'called': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'address': 0.60; 'relationship': 0.60; 'company': 0.60; 'customer': 0.61; 'more': 0.63; 'person,': 0.65; 'believe': 0.69; 'business': 0.70; 'customers': 0.71; 'military': 0.71; 'blow': 0.84; 'ltd"': 0.84; 'say:': 0.84; 'subject:good': 0.84; 'corporations': 0.93; 'army': 0.95 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:to :content-type; bh=xVyJaPUQZE7UkX7qZnF6WnoO0ofSo+joiOuF7Ut/v0o=; b=uNUP6RszLMVkPoqg6ElCMrunf2QqKX0BIq8aN6jU3xCBI69NSGnACJpf5oJYoWWaiZ b0cB5WEez30X6j6NkKLdJKxUe+SrC50rp6Vub620DnStC4yRTJisL2bY2kx8gx9rujJk JFIbxVXUQ79ULwFJmyEx6KCv76xY/8EIXTTsn0FVWzaHkf1MjsUALEyGd+9ZnsNx88Fk cxIdedYAa/NAzSod2jd9PUckAiFVsNAI6VjlxZvo8xUrraDhMGTVhyKiQjhNXjbvKc96 IQcC7Z3MmLhNbgvcsk7OHs2Xi9yaIfJjsWMGW1XA0nhqkEQSA9HgNWWLiBnNq0jnGW/8 Qjgg== MIME-Version: 1.0 In-Reply-To: <5022a1bb$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <54b916fe-9e2d-4f9e-b533-b5ecf677c8a5@a19g2000vba.googlegroups.com> <501f0e4a$0$29867$c3e8da3$5496439d@news.astraweb.com> <5020a544$0$29867$c3e8da3$5496439d@news.astraweb.com> <6-GdneHMxPM-QL3NnZ2dnUVZ8nSdnZ2d@bt.com> <502122ce$0$29978$c3e8da3$5496439d@news.astraweb.com> <0PWdnX8z0uIx1LzNnZ2dnUVZ8vmdnZ2d@bt.com> <65e77682-00ab-4e86-b3cb-2046d6e5c628@r2g2000pbn.googlegroups.com> <5022a1bb$0$29978$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 9 Aug 2012 11:32:00 +1000 Subject: Re: Looking for a good introduction to object oriented programming with Python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344475924 news.xs4all.nl 6958 [2001:888:2000:d::a6]:43589 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26773 On Thu, Aug 9, 2012 at 3:28 AM, Steven D'Aprano wrote: > (As they say: I'll believe that corporations are people when Texas > executes one.) If proper excuse you can trump any, You may wind up a Limited Company You cannot conveniently blow it up! -- WS Gilbert, "Utopia, Ltd" But not every "is-a" relationship needs to be represented as class inheritance. So what if all your Customers are Persons? Do you _really_ need a Person base class? In a lot of systems, you don't. If anything, you might have a generic base class for every entity that has an Address (which would include corporations), but that's more likely to want to be composition than inheritance (the customer Has-An Address rather than the customer Is-An AddressibleEntity). Flat is better than nested. Of course, if you don't need an actual use-case, I could invent several ridiculous base classes. Why not have one for Body, which would be subclassed by Person and Corporation (after all, a corporation is a body, that's where the name comes from), but not Ghost. And then you could have a mixin called Intelligence which is used by Corporation and Army (everyone knows what Business Intelligence and Military Intelligence are), sometimes used by Person, but never used by ClassDesign. ChrisA