a single class supporting multiple facets/interfaces

David Garamond davegaramond at icqmail.com
Wed Jan 22 08:50:54 CET 2003

Terry Reedy wrote:
>>the above code does what i want to accomplish, but i think it's very
>>ugly. can anyone make it more elegant?
> I am slightly surprised at how often people post questions like the
> above.
> To me, any code which is straightforward (comprehensible on one
> reading), easy to change, and which accomplishes the goal intended,
> has a certain kind of beauty.
> Code does not have to be ugly to be improvable.

agreed. and that's why i didn't think my code was elegant/beautiful: 
it's not straightforward. all i need is to create some kind of mapping 
between method names (C's foo1 -> facet1's foo, C's foo2 -> facet2's 
foo) so C's client can pick a facet she wants and C will make foo refer 
to the correct implementation. but i ended up creating two different 
'facet' classes. it's the two classes that i want to eliminate.

> That said, I believe you could also do what you want by deriving your
> master class from object (to make it 'new-style') and the facet
> classes from the master class.  Then provide a factory function which
> returns an instance of the desired subclass.
> Something like


More information about the Python-list mailing list