forked from Sean-Bradley/Design-Patterns-In-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract_document.py
53 lines (43 loc) · 1.3 KB
/
abstract_document.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
"An abstract document containing a combination of hooks and abstract methods"
from abc import ABCMeta, abstractmethod
class AbstractDocument(metaclass=ABCMeta):
"A template class containing a template method and primitive methods"
@staticmethod
@abstractmethod
def title(document):
"must implement"
@staticmethod
def description(document):
"optional"
@staticmethod
def author(document):
"optional"
@staticmethod
def background_colour(document):
"optional with a default behavior"
document["background_colour"] = "white"
@staticmethod
@abstractmethod
def text(document, text):
"must implement"
@staticmethod
def footer(document):
"optional"
@staticmethod
def print(document):
"optional with a default behavior"
print("----------------------")
for attribute in document:
print(f"{attribute}\t: {document[attribute]}")
print()
@classmethod
def create_document(cls, text):
"The template method"
_document = {}
cls.title(_document)
cls.description(_document)
cls.author(_document)
cls.background_colour(_document)
cls.text(_document, text)
cls.footer(_document)
cls.print(_document)