Factory

The aim of a creational design pattern is to provide better alternatives for situations where a direct object creation (which in Python happens by the init() function [j.mp/divefunc], [Lott14, page 26]) is not convenient.

In the Factory design pattern, a client asks for an object without knowing where the object is coming from(that is, which class is used to generate it).

class Point3:
    def __init__(self, x, y):
        self.x = x
        self.y = y 

    def __str__(self):
        return f"x: {self.x}, y: {self.y}"
    class PointFactory:
        @staticmethod
        def new_cartesian_point(x, y):
            return Point3(x, y) 
        @staticmethod
        def new_polar_point(rho, theta):
            return Point3(rho * cos(theta), rho * sin(theta))

    factory = PointFactory()

code