Changing class membership

Roland Schlenker rol9999 at attglobal.net
Thu Sep 28 14:39:26 CEST 2000


Why not use a proxy pattern object:

def TextProxy:
    def __init__(self):
        self.text = None
    def getText(self):
        if self.text == None:
            self.text = get text on harddrive
        return self.text

Roland Schlenker

Dirk-Ulrich Heise wrote:

> How do i most elegantly let an object switch its class
> membership? My problem is, i have a sort of proxy object
> with a name. When this proxy object gets a certain request
> (especially, for a text it represents), it can't answer this
> request because it doesn't have the info. But it knows
> where to look on the harddisk, so it will load this text,
> magically become a "real object" (no more a proxy, but
> now a full-fitted object that has all its info), and answer the
> request.
>
> On later requests, it will have forgotten about it's infant
> proxy status but simply tell everybody the info it has now.
>
> I guess that's called "switching modes". Hmm. Maybe,
> for now i'll simply switch with a bool member. Anyway,
> somebody used mode switching out there? Pros?
> Cons? Advice for this design decision?
>
> --
> Dipl.Inform. Dirk-Ulrich Heise
> hei at adtranzsig.de
> dheise at debitel.net




More information about the Python-list mailing list