modifying classes used by other classes

gcash gcash at luncheonmeat.cfl.rr.com
Fri Apr 26 21:51:03 EDT 2002


OK, here's a rough question in OOP that I've been tangling with...

I've tried googling about it, but I'm not even really sure of my
terminology, so that's not been much help.

So you've got a module that defines 2 classes: spam is the main class to be
used by apps, and it instantiates a whole bunch of "eggs".

class eggs:
   def __init__:
      ...

   def scramble:
      ...

   def drop:
      ...

class spam:
   def __init__:
      ...

   def ham:
      ...
      <instantiate a whole bunch of eggs as sub-objects>
      ...

The problem is you want to override methods of eggs.  You can subclass eggs
all you want, but since spam doesn't use your subclass, you're out of luck.
You're reduced to ugly things like setting methods of eggs equal to
functions you define.

Should I pass the class for eggs as an argument to spam's __init__, which
defaults to the eggs defined by the module?  That seems rather clumsy in a
lot of ways.

A more concrete example: a tkinter tree widget class that creates a
structure of a whole bunch of node instances, each node representing a
folder in the tree.

What would the best way for a user to alter the node class so it binds a
certain mouse click to it's symbol when instantiated?

Another example: a GPS class which creates lists of track, route, and
waypoint instances - how do I best override the __repr__ for the track
class, so it prints the way I want?

What's the best OOP term for classes like "eggs", anyways?  "Helper class"?
It's definitely not a mix-in, obviously.  "Helper class" didn't show up
much on google, though.

-gc

-- 
It was pretty sad, really. When I heard him start to explain 56K, it was
like watching someone try to explain quantum physics to a goat.  At that
point, though, he had no choice it was like the Titanic after the iceberg,
just a matter of time until the people started screaming.



More information about the Python-list mailing list