Logo

Programming-Idioms

History of Idiom 73 > diff from v310 to v311

Edit summary for version 311 by :

Version 310

2015-10-31, 15:32:37

Version 311

2015-11-30, 12:37:30

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(a_class, Parent):
        return a_class(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
Comments bubble
this is not needed in python you can use the class like a function