-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_Shape.py
50 lines (39 loc) · 1.29 KB
/
05_Shape.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
46
47
48
49
50
from abc import ABC, abstractmethod
# Abstract Class: Shape
class Shape(ABC):
@abstractmethod
def draw(self):
pass
# Abstract Class: Color
class Color(ABC):
@abstractmethod
def apply_color(self):
pass
# Concrete Class implementing Shape and Color (Multiple Inheritance)
class ColoredShape(Shape, Color):
def __init__(self, color):
self.color = color
def draw(self):
return f"Drawing a {self.color} shape."
def apply_color(self):
return f"Applying {self.color} color."
# Concrete Class implementing only Shape
class Circle(Shape):
def draw(self):
return "Drawing a circle."
# Concrete Class implementing only Color
class RedColor(Color):
def apply_color(self):
return "Applying red color."
# Function demonstrating the use of classes with multiple inheritance
def process_shapes_and_colors(shapes_and_colors):
for obj in shapes_and_colors:
print(obj.draw())
print(obj.apply_color())
print("\n")
# Creating instances of concrete classes
colored_circle = ColoredShape(color="blue")
simple_circle = Circle()
red_color = RedColor()
# Using the process_shapes_and_colors function with a list of objects
process_shapes_and_colors(shapes_and_colors=[colored_circle, simple_circle, red_color])