factory pattern the factory method when we want to call method such that we pass in string and get as return value new objectwe are essentially calling factory method the type of the object is determined by the string that is passed to the method this makes it easy to extend the code you write by allowing you to add functionality to your softwarewhich is accomplished by adding new class and extending the factory method to accept new string and return the class you created let' look at simple implementation of the factory method shape_ factory py import pygame class shape(object)def __init__(selfxy)self self def draw(self)raise notimplementederror(def move(selfdirection)if direction ='up'self - elif direction ='down'self + elif direction ='left'self - elif direction ='right'self + @staticmethod def factory(type)if type ="circle"return circle( if type ="square"return square(