Logo

Programming-Idioms

History of Idiom 73 > diff from v322 to v323

Edit summary for version 323 by programming-idioms.org:
[Python] pFact -> fact

Version 322

2016-06-12, 16:55:24

Version 323

2016-06-12, 16:56:11

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 fact(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
In Python you can use the class like a function.