formations/algo/poo/cours/snippets/patrons.py

19 lines
294 B
Python
Raw Normal View History

2017-09-05 09:25:48 +02:00
class NotFoundError(Exception):
pass
class MaClasse:
pass
class MaClasseDeux:
pass
binding = dict(un=MaClasse, deux=MaClasseDeux)
def ma_factory(key):
if key in binding:
return binding[key]()
else:
return NotFoundError("keskece?")