Python中的外观模式

问题描述 投票:-1回答:1

我试图应用类似于Java中的概念的外观模式,但是我认为这是不正确的。我认为ShapeMaker类或Main中有问题,您认为这里有问题吗?

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()
python python-3.x design-patterns facade
1个回答
0
投票

我在drawRectangle方法中不小心将其称为圆。这是更正的版本。

© www.soinside.com 2019 - 2024. All rights reserved.