Default attribute in base class precludes delegation

Gabriel Genellina gagenellina at softlab.com.ar
Fri Dec 19 02:07:27 EST 2003


At 19/12/2003 05:41, you wrote:

> >- a Derived class which must inherit from Base and is a wrapper around
> >Worker: it contains a Worker instance and delegates almost anything to it.
> >This class can be modified as needed too.
>In what sense a "wrapper"?

In fact it's an Adapter: it contains a reference to the Worker -and 
delegates most method calls to it- also providing the interfase expected 
from Base.

> >For most attributes, as they are not found in the Derived instance's dict,
> >__getattr__ is called and the attribute is retrieved from the Worker 
> instance.
>Why do you (think you) need an explicit __getattr__ ? Usually there's 
>better ways.

How?

>class Derived(Worker, Base):
>     """dummy until something to do"""
>
>Or do you actually need to have different unknown types of workers so you 
>can't inherit?

Oh, thanks but that won't work. There are many types of Workers, chosen at 
run time, that's why I can't simply inherit and have to use delegation.


Gabriel Genellina
Softlab SRL






More information about the Python-list mailing list