Pattern question
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Jul 8 11:42:19 EDT 2005
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
More information about the Python-list
mailing list