-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractfactory.py
More file actions
80 lines (62 loc) · 1.66 KB
/
Copy pathAbstractfactory.py
File metadata and controls
80 lines (62 loc) · 1.66 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from abc import ABC, abstractmethod
class Car(ABC):
@abstractmethod
def drive(self):
pass
@abstractmethod
def get_info(self):
pass
class BenzSUV(Car):
def drive(self):
print("Driving a Benz SUV")
def get_info(self):
return "Benz SUV"
class BenzCoupe(Car):
def drive(self):
print("Driving a Benz Coupe")
def get_info(self):
return "Benz Coupe"
class BmwSUV(Car):
def drive(self):
print("Driving a BMW SUV")
def get_info(self):
return "BMW SUV"
class BmwCoupe(Car):
def drive(self):
print("Driving a BMW Coupe")
def get_info(self):
return "BMW Coupe"
class CarFactory(ABC):
@abstractmethod
def create_suv(self) -> Car:
pass
@abstractmethod
def create_coupe(self) -> Car:
pass
class BenzFactory(CarFactory):
def create_suv(self) -> Car:
return BenzSUV()
def create_coupe(self) -> Car:
return BenzCoupe()
class BmwFactory(CarFactory):
def create_suv(self) -> Car:
return BmwSUV()
def create_coupe(self) -> Car:
return BmwCoupe()
def main():
brand = input("Enter car brand (Benz/BMW): ").strip().lower()
if brand == "benz":
factory = BenzFactory()
elif brand == "bmw":
factory = BmwFactory()
else:
print("Unsupported brand")
return
suv = factory.create_suv()
coupe = factory.create_coupe()
print(f"Created: {suv.get_info()}")
suv.drive()
print(f"Created: {coupe.get_info()}")
coupe.drive()
if __name__ == "__main__":
main()