-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecathlonFactory.py
More file actions
95 lines (72 loc) · 2.25 KB
/
Copy pathDecathlonFactory.py
File metadata and controls
95 lines (72 loc) · 2.25 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""Design and Implement an AbstractFactory class to create families of related or
dependent objects with respect to decathlon store without specifying their concrete
classes using Abstract Factory."""
from abc import ABC, abstractmethod
# Abstract Product classes
class SportEquipment(ABC):
@abstractmethod
def get_name(self):
pass
@abstractmethod
def get_price(self):
pass
class Apparel(ABC):
@abstractmethod
def get_name(self):
pass
@abstractmethod
def get_price(self):
pass
# Concrete Product classes for Running
class RunningShoes(SportEquipment):
def get_name(self):
return "Decathlon Running Shoes"
def get_price(self):
return 50.0
class RunningTShirt(Apparel):
def get_name(self):
return "Decathlon Running T-Shirt"
def get_price(self):
return 20.0
# Concrete Product classes for Cycling
class CyclingHelmet(SportEquipment):
def get_name(self):
return "Decathlon Cycling Helmet"
def get_price(self):
return 30.0
class CyclingGloves(Apparel):
def get_name(self):
return "Decathlon Cycling Gloves"
def get_price(self):
return 15.0
# Abstract Factory class
class DecathlonFactory(ABC):
@abstractmethod
def create_sport_equipment(self):
pass
@abstractmethod
def create_apparel(self):
pass
# Concrete Factory classes
class RunningFactory(DecathlonFactory):
def create_sport_equipment(self):
return RunningShoes()
def create_apparel(self):
return RunningTShirt()
class CyclingFactory(DecathlonFactory):
def create_sport_equipment(self):
return CyclingHelmet()
def create_apparel(self):
return CyclingGloves()
# Client code
def create_decathlon_products(factory: DecathlonFactory):
equipment = factory.create_sport_equipment()
apparel = factory.create_apparel()
print(f"Equipment: {equipment.get_name()}, Price: ${equipment.get_price()}")
print(f"Apparel: {apparel.get_name()}, Price: ${apparel.get_price()}")
running_factory = RunningFactory()
cycling_factory = CyclingFactory()
print("Running Products:")
create_decathlon_products(running_factory)
print("\nCycling Products:")
create_decathlon_products(cycling_factory)