Factory pattern Python