sample python implementation example description let us consider an example to demonstrate the usage of factory pattern (based on example of factory pattern in java from allapplabs com we have base class called person that has methods for getting the name and the gender and has two sub-classes namely male and female that print the salutation message and factory class factory class has method named 'getpersonthat takes two arguments 'nameand 'genderof person the client instantiates the factory class and calls the getperson method with name and gender as arguments during run-timebased on the genderthat is passed by the clientthe factory creates an object of the class pertaining to that gender hence the factory class at run-time decides which object it needs to create python code class persondef __init__(self)self name none self gender none def getname(self)return self name def getgender(self)return self gender class male(person)def __init__(selfname)print "hello mr name class female(person)def __init__(selfname)print "hello miss name class factorydef getperson(selfnamegender)if gender =' 'return male(nameif gender =' 'return female(name www testingperspective com