python中的工厂设计模式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

以上是关于python中的工厂设计模式的主要内容,如果未能解决你的问题,请参考以下文章

python简单工厂模式解析

设计模式第二谈:工厂方法模式

设计模式(Python)-简单工厂,工厂方法和抽象工厂模式

Python设计模式:工厂方法模式

工厂模式的python实现

python实现简单工厂模式