Adding an interface to existing classes

Terry Reedy tjreedy at udel.edu
Thu Dec 22 18:13:42 EST 2011


On 12/22/2011 3:21 AM, Spencer Pearson wrote:
> I'm writing a geometry package, with Points and Lines and Circles and
> so on, and eventually I want to be able to draw these things on the
> screen. I have two options so far for how to accomplish this, but
> neither of them sits quite right with me, and I'd like the opinion of
> comp.lang.python's wizened elders.
>
> Option 1. Subclassing.
> The most Pythonic way would seem to be writing subclasses for the
> things I want to display, adding a ".draw(...)" method to each one,
> like this:

> Option 2. A "draw" function, with a function dictionary.

Option 3? Add a draw method to existing classes, rather than subclassing?

-- 
Terry Jan Reedy




More information about the Python-list mailing list