-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract_factory_ui.py
95 lines (60 loc) · 2.2 KB
/
abstract_factory_ui.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
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
# source : https://www.tutorialspoint.com/python_design_patterns/python_design_patterns_abstract_factory.htm
# with small adaptations to keep same style across examples
class Window:
__toolkit = ""
__purpose = ""
def __init__(self, toolkit, purpose):
self.__toolkit = toolkit
self.__purpose = purpose
def getToolkit(self):
return self.__toolkit
def getType(self):
return self.__purpose
class GtkToolboxWindow(Window):
def __init__(self):
Window.__init__(self, "Gtk", "ToolboxWindow")
class GtkLayersWindow(Window):
def __init__(self):
Window.__init__(self, "Gtk", "LayersWindow")
class GtkMainWindow(Window):
def __init__(self):
Window.__init__(self, "Gtk", "MainWindow")
class QtToolboxWindow(Window):
def __init__(self):
Window.__init__(self, "Qt", "ToolboxWindow")
class QtLayersWindow(Window):
def __init__(self):
Window.__init__(self, "Qt", "LayersWindow")
class QtMainWindow(Window):
def __init__(self):
Window.__init__(self, "Qt", "MainWindow")
class AbstractFactoryUI:
def getToolboxWindow(self): pass
def getLayersWindow(self): pass
def getMainWindow(self): pass
class GtkUIFactory(AbstractFactoryUI):
def getToolboxWindow(self):
return GtkToolboxWindow()
def getLayersWindow(self):
return GtkLayersWindow()
def getMainWindow(self):
return GtkMainWindow()
class QtUIFactory(AbstractFactoryUI):
def getToolboxWindow(self):
return QtToolboxWindow()
def getLayersWindow(self):
return QtLayersWindow()
def getMainWindow(self):
return QtMainWindow()
def client(factory: AbstractFactoryUI) -> None:
main = factory.getMainWindow()
layers = factory.getLayersWindow()
toolbox = factory.getToolboxWindow()
print(f"{main.getToolkit()} : {main.getType()}")
print(f"{layers.getToolkit()} : {layers.getType()}")
print(f"{toolbox.getToolkit()} : {toolbox.getType()}")
if __name__ == "__main__":
print("\nClient: Testing client code with Factory Type GtkUIFactory:")
client(GtkUIFactory())
print("\nClient: Testing client code with Factory Type QtUIFactory:")
client(QtUIFactory())