-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype_pattern.py
More file actions
43 lines (29 loc) · 852 Bytes
/
prototype_pattern.py
File metadata and controls
43 lines (29 loc) · 852 Bytes
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
import copy
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def draw(self):
pass
class Square(Shape):
def __init__(self, size):
self.size = size
def draw(self):
print(f"Drawing a square of size{self.size}")
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def draw(self):
print(f"Drawing a circle of radius {self.radius}")
class AbstractArt:
def __init__(self, bg_color, shapes):
self.bg_color = bg_color
self.shapes = shapes
def draw(self):
print(f"Background color is {self.bg_color}")
[x.draw() for x in shapes]
if __name__ == "__main__":
shapes = [Square(5), Square(3), Circle(8)]
art_1 = AbstractArt("red", shapes)
art_2 = copy.copy(art_1)
art_1.draw()
art_2.draw()