Posted By

silviud on 07/18/10


Tagged

python patterns design factory


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

saman


factory design pattern in python


 / Published in: Python
 

  1. """
  2. params is a string of the class that you want
  3.  
  4. example:
  5.  
  6. my_class = "do_something"
  7.  
  8. instance = factory(my_class)
  9.  
  10. the name module is hard coded ...
  11.  
  12. """
  13.  
  14. def factory(cls_string, *args):
  15. cls = getattr(module, cls_string)
  16. return apply(cls, args)

Report this snippet  

You need to login to post a comment.