Circular Inheritance

Ian Bicking ianb at colorstudy.com
Wed Jul 2 01:49:36 EDT 2003


On Tue, 2003-07-01 at 19:00, Ben Finney wrote:
> Re-design the modules so that inheritance is a hierarchy.  A band-aid
> solution may be to create a new class that mediates between two others,
> breaking the circle.  Much better is to figure out why the classes need
> to know so much about each other, and redesign them with smaller,
> simpler interfaces.

It seems quite reasonable to have circular dependencies between two or
more classes.  The most common case being that one class references the
other, and the other class has back references.  Very common, and it
doesn't imply that the classes know too much about each other.

You might encounter less problems if those classes go together in a
single module, but module boundaries are just there to help the
programmer organize code, they have little formal meaning.

> Even if there were a way to do circular inheritance, it would be a
> nightmare to understand, so needs to be redesigned anyway.

He probably just meant circular dependency, since obviously inheritance
doesn't make sense.

  Ian







More information about the Python-list mailing list