Is a factory pattern meaningless in Python?

Since Python is a duck language, does it write factory classes that are meaningless in Python? http://en.wikipedia.org/wiki/Factory_method_pattern

+5
source share
2 answers

Although there may be times when a factory template is not needed, where it may be required in other languages, there are still times when it would be advisable to use it - maybe this is just a way to make your API cleaner - for example, as a way to prevent code duplication, which decides which of the following subclasses to return.

From the Wikipedia article you linked:

Use the factory pattern if:

  • .
  • , .
  • .

, .

+12

factory, Python factory: http://docs.python.org/library/collections.html#collections.namedtuple.

, , , , type() .

, , Python , . factory, factory .

+4

All Articles