vendredi 8 mai 2020

Facade Pattern in Python

I tried to apply a facade pattern similar to the concept I did in Java, but I don't think it's exactly right. I think there is a problem in the ShapeMaker class or Main, do you think there is a problem here?

from __future__ import annotations

class Rectangle:
    def draw(self):
        print("Rectangle draw()")

class Square:
    def draw(self):
        print("Square draw()")

class Circle:
    def draw(self):
        print("Circle draw()")

class ShapeMaker:
    def __init__(self) -> None:
        self.rectangle = Rectangle()
        self.square = Square()
        self.circle = Circle()

    def drawRectangle(self):
        self.circle.draw()

    def drawSquare(self):
        self.square.draw()

    def drawCircle(self):
        self.circle.draw()

if __name__ == "__main__":
    shapemaker = ShapeMaker()
    shapemaker.drawCircle()
    shapemaker.drawSquare()
    shapemaker.drawRectangle()

Aucun commentaire:

Enregistrer un commentaire