Puzzling OO design problem

Jack Diederich jack at performancedrivers.com
Fri Apr 8 20:13:25 EDT 2005


On Fri, Apr 08, 2005 at 04:42:52PM -0700, George Sakkis wrote:
> I'm looking for a design to a problem I came across, which goes like
> this (no, it's not homework):
> 
> 1. There is a (single inheritance) hierarchy of domain classes, say
> A<-B<-..<-Z (arrows point to the parent in the inheritance tree).
> 2. This hierarchy evolved over time to different versions for each
> class. So for example, version's 1 hierarchy would be A_v1 <-B_v1
> <-..<-Z_v1.
> 3. At runtime, only one version is selected by a factory function.
> 
> Up to this point, the inheritance graph would be the following:
> 
> A <- A_V1 ... <- A_Vn
> ^     ^           ^
> |     |           |
> B <- B_V1 ... <- B_Vn
> .     .           .
> .     .           .
> .     .           .
> ^     ^           ^
> |     |           |
> Z <- Z_V1 ... <- Z_Vn
> 
> 
> This could be implemented either with multiple inheritance (e.g.
> B_V1(B,A_V1)) or using the bridge design pattern |Z| times, one per
> each row. Both solutions would be acceptable; there are no ambiguities
> caused by the multiple inheritance (or they are resolved properly
> whenever they occur).
> 
> Now the problem is that there are 'holes' in this inheritance lattice:
> Not all versions introduced new variations of all types; for instance
> B_V5 could be missing, meaning that the most recent earlier version of
> B would be used in version 5 (say B_V2). My first thought was to create
> all the missing classes dynamically, but it's somewhat obscure and it
> may not be that simple. Is there a more elegant solution, either a
> general design pattern or some clever python metaprogramming hack ?
> 

Err, you might want to explain what these things do instead of an
abstract description of how you are doing it.  It looks like you are
using inheritance in the normal way _and_ you are using it to handle
versioning of some kind (maybe stable interface releases? I don't know).

Let us know what parts need inheritance for, and what you have
just been using a side effect of inheritance for as a convenience
(versioning, I think).

A more concrete example would be easier to comment on, if possible
do a simple one (maybe just two classes with two versions each).

-jackdied



More information about the Python-list mailing list