-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecorator_pattern.py
47 lines (34 loc) · 1.13 KB
/
decorator_pattern.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Shape:
def draw(self):
pass
class Rectangle(Shape):
def draw(self):
print("Shape: Rectangle")
class Circle(Shape):
def draw(self):
print("Shape : Circle")
class ShapeDecorator(Shape):
def __init__(self, decorated_shape: 'Shape'):
self.decorated_shape = decorated_shape
def draw(self):
self.decorated_shape.draw()
class RedShapeDecorator(ShapeDecorator):
def __init__(self, decorated_shape: 'Shape'):
ShapeDecorator.__init__(self, decorated_shape)
def draw(self):
self.decorated_shape.draw()
self.setRedBorder(self.decorated_shape)
def setRedBorder(self, decorated_shape: 'Shape'):
print("Border Color: Red")
class GreenShapeDecorator(ShapeDecorator):
def __init__(self, decorated_shape: 'Shape'):
ShapeDecorator.__init__(decorated_shape)
def draw(self):
self.decorated_shape.drwa()
self.setRedBorder(self.decorated_shape)
def setRedBorder(self, decorated_shape: 'Shape'):
print("Border Color: Green")
circle = Circle()
red_circle = RedShapeDecorator(circle)
circle.draw()
red_circle.draw()