building embedded classes as in C/C++

Tres Seaver tseaver at starbase.neosoft.com
Thu Aug 5 05:33:15 CEST 1999


In article <slrn7qf4g2.3vvqed5.mmorris at finin.morrisland.com>,
Mitchell Morris <mmorris at mindspring.com> wrote:

>Of course it is ... everything is possible in Python, since it is Turing
>complete. On a different philosophical note, there are two concepts which
>can be expressed best by inheritance (according to the conventional C++
>wisdom which I'll parrot to the best of my ability).
>
>The most common notion is "is-a", modeled in C++ by public inheritance.
>For example, "class Penguin(Bird)" conceptually represents the notion that a
>penguin is a bird and thus could be expected to do anything a bird can do and
>respond to any input that other birds would respond to.
>
>The other common notion expressed by inheritance is "is-implemented-by".
>For example, "class TCPSocket(File)" conceptually means that a TCPSocket
>works exactly like a file, so we'll be stealing his methods directly instead
>of writing our own. In C++ this would likely be accomplished through
>private inheritance.
>
>Extra credit if you can think of an example that matches protected
>inheritance.

"Ooh! ooh!"  The classic usage is to model "is-implemented-by-for-my-kids-sake"
behavior:  

    AbstractFoo
         ^
		 +-------------+
		 |             |
    (protected)  (public,virtual)
		 |             |
   CommonFooImpl       |
		 ^             +
		 +-private--+OneOfManyDerivedFOos

The derived classes can exploit the AbstractFoo-ness of CommonFooImpl, but
nobody else can.

>
>Since your example classes "Object" and "Point" actually model neither 
>"is-a" nor "is-implemented-by", you may take as a first approximation that
>inheritance isn't going to work for you here.
>
>
>hoping-some-of-this-helps-ly y'rs,
>+Mitchell
>
>(Dang, now you've got me hyphenating!)

It's-catching-idn't-it-ly,

Tres.


-- 
---------------------------------------------------------------
Tres Seaver           tseaver at palladion.com       713-523-6582
Palladion Software    http://www.palladion.com




More information about the Python-list mailing list