9
9
10
10
11
11
class Model (ABC ):
12
+ """The Model is the data layer of the application."""
12
13
@abstractmethod
13
14
def __iter__ (self ):
14
15
pass
@@ -26,6 +27,7 @@ def item_type(self) -> str:
26
27
27
28
28
29
class ProductModel (Model ):
30
+ """The Model is the data layer of the application."""
29
31
class Price (float ):
30
32
"""A polymorphic way to pass a float with a particular
31
33
__str__ functionality."""
@@ -52,12 +54,13 @@ def get(self, product: str) -> dict:
52
54
53
55
54
56
class View (ABC ):
57
+ """The View is the presentation layer of the application."""
55
58
@abstractmethod
56
59
def show_item_list (self , item_type : str , item_list : dict ) -> None :
57
60
pass
58
61
59
62
@abstractmethod
60
- def show_item_information (self , item_type : str , item_name : str , item_info : str ) -> None :
63
+ def show_item_information (self , item_type : str , item_name : str , item_info : dict ) -> None :
61
64
"""Will look for item information by iterating over key,value pairs
62
65
yielded by item_info.items()"""
63
66
pass
@@ -68,17 +71,20 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
68
71
69
72
70
73
class ConsoleView (View ):
74
+ """The View is the presentation layer of the application."""
71
75
def show_item_list (self , item_type : str , item_list : dict ) -> None :
72
76
print (item_type .upper () + " LIST:" )
73
77
for item in item_list :
74
78
print (item )
75
79
print ("" )
76
80
77
81
@staticmethod
78
- def capitalizer (string ) -> str :
82
+ def capitalizer (string : str ) -> str :
83
+ """Capitalizes the first letter of a string and lowercases the rest."""
79
84
return string [0 ].upper () + string [1 :].lower ()
80
85
81
- def show_item_information (self , item_type , item_name , item_info ) -> None :
86
+ def show_item_information (self , item_type : str , item_name : str , item_info : dict ) -> None :
87
+ """Will look for item information by iterating over key,value pairs"""
82
88
print (item_type .upper () + " INFORMATION:" )
83
89
printout = "Name: %s" % item_name
84
90
for key , value in item_info .items ():
@@ -91,9 +97,10 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
91
97
92
98
93
99
class Controller :
94
- def __init__ (self , model_class , view_class ) -> None :
95
- self .model = model_class
96
- self .view = view_class
100
+ """The Controller is the intermediary between the Model and the View."""
101
+ def __init__ (self , model_class : Model , view_class : View ) -> None :
102
+ self .model : Model = model_class
103
+ self .view : View = view_class
97
104
98
105
def show_items (self ) -> None :
99
106
items = list (self .model )
@@ -106,22 +113,23 @@ def show_item_information(self, item_name: str) -> None:
106
113
:param str item_name: the name of the {item_type} item to show information about
107
114
"""
108
115
try :
109
- item_info = self .model .get (item_name )
116
+ item_info : str = self .model .get (item_name )
110
117
except Exception :
111
- item_type = self .model .item_type
118
+ item_type : str = self .model .item_type
112
119
self .view .item_not_found (item_type , item_name )
113
120
else :
114
- item_type = self .model .item_type
121
+ item_type : str = self .model .item_type
115
122
self .view .show_item_information (item_type , item_name , item_info )
116
123
117
124
118
125
class Router :
126
+ """The Router is the entry point of the application."""
119
127
def __init__ (self ):
120
128
self .routes = {}
121
129
122
- def register (self , path : str , controller_class , model_class , view_class ) -> None :
123
- model_instance = model_class ()
124
- view_instance = view_class ()
130
+ def register (self , path : str , controller_class : Controller , model_class : Model , view_class : View ) -> None :
131
+ model_instance : Model = model_class ()
132
+ view_instance : View = view_class ()
125
133
self .routes [path ] = controller_class (model_instance , view_instance )
126
134
127
135
def resolve (self , path : str ) -> Controller :
0 commit comments