factory design pattern in python


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.