-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype_pattern.py
More file actions
42 lines (32 loc) · 1.11 KB
/
prototype_pattern.py
File metadata and controls
42 lines (32 loc) · 1.11 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
import copy
from abc import *
from typing import Self
class DocumentTemplate(ABC):
@abstractmethod
def peek(self) -> None: ...
@abstractmethod
def clone(self) -> Self: ...
class JobApplyTemplate(DocumentTemplate):
def __init__(self, title: str, body: str, stack: str):
self.title = title
self.body = body
self.stack = stack
def peek(self) -> None:
print(f"{self.title}, {self.body}, {self.stack}")
def clone(self) -> Self:
return copy.deepcopy(self)
class InviteTemplate(DocumentTemplate):
def __init__(self, person_name: str, date: str):
self.person_name = person_name
self.data = date
def peek(self) -> None:
print(f"{self.person_name} tryna hangout at {self.date}?")
def clone(self) -> Self:
return copy.deepcopy(self)
def main():
first_application = JobApplyTemplate(title='a', body='b', stack='c')
first_application.peek()
second_application = first_application.clone()
second_application.peek()
if __name__ == '__main__':
main()