Logo

Programming-Idioms

History of Idiom 73 > diff from v391 to v392

Edit summary for version 392 by programming-idioms.org:
[Python] Conciseness

Version 391

2017-02-01, 20:11:43

Version 392

2017-05-12, 12:10:42

Idiom #73 Create a factory

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

Idiom #73 Create a factory

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

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