-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
68 lines (47 loc) · 1.38 KB
/
example.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
from abc import ABC, abstractmethod
class Button(ABC):
@abstractmethod
def render(self):
pass
@abstractmethod
def on_click(self):
pass
class WindowButton(Button):
def render(self):
return "Window: Render button window done"
def on_click(self):
return "Window: Click button window done"
class HTMLButton(Button):
def render(self):
return "HTML: Render button html done"
def on_click(self):
return "HTML: Click html window done"
class Dialog(ABC):
@abstractmethod
def render(self):
pass
def create_button(self):
button = self.render()
result = f"Dialog: Create button \n {button.render()}"
return result
class WindowDialog(Dialog):
def render(self):
return WindowButton()
class HTMLDialog(Dialog):
def render(self):
return HTMLButton()
class ClientCode:
def __init__(self, dialog: Dialog):
self.dialog = dialog
def create_button(self):
print(f"Client: Create button\n {self.dialog.create_button()}", end="")
if __name__ == "__main__":
print("App: I am using window.")
window_dialog = WindowDialog()
client = ClientCode(window_dialog)
client.create_button()
print("\n")
print("App: I am using WEB.")
html_dialog = HTMLDialog()
client = ClientCode(html_dialog)
client.create_button()