Looking for a good introduction to object oriented programming with Python

Chris Angelico rosuav at gmail.com
Wed Aug 8 21:32:00 EDT 2012


On Thu, Aug 9, 2012 at 3:28 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> 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



More information about the Python-list mailing list