Pattern question
cantabile
cantabile.03 at wanadoo.fr
Sat Jul 9 05:03:35 EDT 2005
Scott David Daniels a écrit :
> cantabile wrote:
>
>> bruno modulix a écrit :
>>
>>> You may want to have a look at the Factory pattern...
>>> ... demo of class Factory ...
>
>
> Taking advantage of Python's dynamic nature, you could simply:
> # similarly outrageously oversimplified dummy example
> class Gui(object):
> def __init__(self, installer):
> self.installer = installer
>
> class PosixGui(Gui):
> pass
>
> class Win32Gui(Gui):
> pass
>
> if os.name == 'posix':
> makeGui = PosixGui
> elif os.name == 'win32':
> makeGui = Win32Gui
> else:
> raise "os %s not supported" % os.name
>
>
> class Installer(object):
> def __init__(self, guiFactory):
> self.gui = guiFactory(self)
>
> def main():
> inst = Installer(makeGui)
> return inst.gui.main()
>
> --Scott David Daniels
> Scott.Daniels at Acm.Org
Thank you too for this tip. :)
Coming from C++ (mainly), I'm not used to this dynamic way of doing
things. That's usefull.
More information about the Python-list
mailing list