-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabstract_factory_code.py
More file actions
146 lines (105 loc) · 3.29 KB
/
abstract_factory_code.py
File metadata and controls
146 lines (105 loc) · 3.29 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
An Implmentation of the Abstract Factory Design Pattern
"""
from abc import ABC, abstractmethod
class Browser(ABC):
"""
Creates "Abstract Product A"
"""
# Interface - Create Search Toolbar
@abstractmethod
def create_search_toolbar(self):
pass
# Interface - Create Browser Window
@abstractmethod
def create_browser_window(self):
pass
class Messenger(ABC):
"""
Creates "Abstract Product B"
"""
@abstractmethod
# Interface - Create Messenger Window
def create_messenger_window(self):
pass
class VanillaBrowser(Browser):
"""
Type: Concrete Product
Abstract methods of the Browser base class are implemented.
"""
# Interface - Create Search Toolbar
def create_search_toolbar(self):
print("Search Toolbar Created")
# Interface - Create Browser Window]
def create_browser_window(self):
print("Browser Window Created")
class VanillaMessenger(Messenger):
"""
Type: Concrete Product
Abstract methods of the Messenger base class are implemented.
"""
# Interface - Create Messenger Window
def create_messenger_window(self):
print("Messenger Window Created")
class SecureBrowser(Browser):
"""
Type: Concrete Product
Abstract methods of the Browser base class are implemented.
"""
# Abstract Method of the Browser base class
def create_search_toolbar(self):
print("Secure Browser - Search Toolbar Created")
# Abstract Method of the Browser base class
def create_browser_window(self):
print("Secure Browser - Browser Window Created")
def create_incognito_mode(self):
print("Secure Browser - Incognito Mode Created")
class SecureMessenger(Messenger):
"""
Type: Concrete Product
Abstract methods of the Messenger base class are implemented.
"""
# Abstract Method of the Messenger base class
def create_messenger_window(self):
print("Secure Messenger - Messenger Window Created")
def create_privacy_filter(self):
print("Secure Messenger - Privacy Filter Created")
def disappearing_messages(self):
print("Secure Messenger - Disappearing Messages Feature Enabled")
class AbstractFactory(ABC):
"""
The Abstract Factory
"""
@abstractmethod
def create_browser(self):
pass
@abstractmethod
def create_messenger(self):
pass
class VanillaProductsFactory(AbstractFactory):
"""
Type: Concrete Factory
Implement the operations to create concrete product objects.
"""
def create_browser(self):
return VanillaBrowser()
def create_messenger(self):
return VanillaMessenger()
class SecureProductsFactory(AbstractFactory):
"""
Type: Concrete Factory
Implement the operations to create concrete product objects.
"""
def create_browser(self):
return SecureBrowser()
def create_messenger(self):
return SecureMessenger()
def main():
for factory in (VanillaProductsFactory(), SecureProductsFactory()):
product_a = factory.create_browser()
product_b = factory.create_messenger()
product_a.create_browser_window()
product_a.create_search_toolbar()
product_b.create_messenger_window()
if __name__ == "__main__":
main()