-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFactoryMethod.py
More file actions
66 lines (40 loc) · 1.21 KB
/
AbstractFactoryMethod.py
File metadata and controls
66 lines (40 loc) · 1.21 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
# Python Code for object
# oriented concepts using
# the abstract factory
# design pattern
import random
class CourseAtGFG:
""" Geeks for Geeks portal for courses """
def __init__(self, courses_factory=None):
"""course factory is out abstract factory"""
self.course_factory = courses_factory
def show_course(self):
"""creates and shows courses using the abstract factory"""
course = self.course_factory()
print(f'We have a course named {course}')
print(f'its price is {course.fee()}')
class DSA:
"""Class for Data Structure and Algorithms"""
def fee(self):
return 11000
def __str__(self):
return "DSA"
class STL:
"""Class for Standard Template Library"""
def fee(self):
return 8000
def __str__(self):
return "STL"
class SDE:
"""Class for Software Development Engineer"""
def fee(self):
return 15000
def __str__(self):
return 'SDE'
def random_course():
"""A random class for choosing the course"""
return random.choice([SDE, STL, DSA])()
if __name__ == "__main__":
course = CourseAtGFG(random_course)
for i in range(5):
course.show_course()