Logo

Programming-Idioms

History of Idiom 73 > diff from v309 to v310

Edit summary for version 310 by :

Version 309

2015-10-29, 14:05:16

Version 310

2015-10-31, 15:32:37

Idiom #73 Create a factory

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Idiom #73 Create a factory

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Code
def pFact(a_class, str):
    if issubclass(Parent, a_class):
        return parent(str)
Code
def pFact(a_class, str_):
    if issubclass(a_class, Parent):
        return a_class(str_)
Comments bubble
this is not needed in python you can use the class like a function