@@ -63,12 +63,12 @@ def show_item_information(self, item_type: str, item_name: str, item_info: str)
63
63
pass
64
64
65
65
@abstractmethod
66
- def item_not_found (self , item_type , item_name ) -> None :
66
+ def item_not_found (self , item_type : str , item_name : str ) -> None :
67
67
pass
68
68
69
69
70
70
class ConsoleView (View ):
71
- def show_item_list (self , item_type , item_list ) -> None :
71
+ def show_item_list (self , item_type : str , item_list : dict ) -> None :
72
72
print (item_type .upper () + " LIST:" )
73
73
for item in item_list :
74
74
print (item )
@@ -86,21 +86,21 @@ def show_item_information(self, item_type, item_name, item_info) -> None:
86
86
printout += "\n "
87
87
print (printout )
88
88
89
- def item_not_found (self , item_type , item_name ) -> None :
89
+ def item_not_found (self , item_type : str , item_name : str ) -> None :
90
90
print (f'That { item_type } "{ item_name } " does not exist in the records' )
91
91
92
92
93
93
class Controller :
94
- def __init__ (self , model , view ) :
95
- self .model = model
96
- self .view = view
94
+ def __init__ (self , model_class , view_class ) -> None :
95
+ self .model = model_class
96
+ self .view = view_class
97
97
98
98
def show_items (self ) -> None :
99
99
items = list (self .model )
100
100
item_type = self .model .item_type
101
101
self .view .show_item_list (item_type , items )
102
102
103
- def show_item_information (self , item_name ) -> None :
103
+ def show_item_information (self , item_name : str ) -> None :
104
104
"""
105
105
Show information about a {item_type} item.
106
106
:param str item_name: the name of the {item_type} item to show information about
@@ -119,15 +119,15 @@ class Router:
119
119
def __init__ (self ):
120
120
self .routes : dict = {}
121
121
122
- def register (self , path : str , controller : object , model : object , view : object ) -> None :
123
- model : object = model ()
124
- view : object = view ()
125
- self .routes [path ] = controller ( model , view )
122
+ def register (self , path : str , controller_class : object , model_class : object , view_class : object ) -> None :
123
+ model_instance : object = model_class ()
124
+ view_instance : object = view_class ()
125
+ self .routes [path ] = controller_class ( model_instance , view_instance )
126
126
127
- def resolve (self , path ) -> Controller :
127
+ def resolve (self , path : str ) -> Controller :
128
128
if self .routes .get (path ):
129
- controller : object = self .routes [path ]
130
- return controller
129
+ controller_class : object = self .routes [path ]
130
+ return controller_class
131
131
else :
132
132
return None
133
133
@@ -170,11 +170,11 @@ def main():
170
170
router .register ("products" , Controller , ProductModel , ConsoleView )
171
171
controller : object = router .resolve (argv [1 ])
172
172
173
- command : str = str (argv [2 ]) if len (argv ) > 2 else ""
173
+ action : str = str (argv [2 ]) if len (argv ) > 2 else ""
174
174
args : str = ' ' .join (map (str , argv [3 :])) if len (argv ) > 3 else ""
175
175
176
- if hasattr (controller , command ):
177
- command = getattr (controller , command )
176
+ if hasattr (controller , action ):
177
+ command = getattr (controller , action )
178
178
sig = signature (command )
179
179
180
180
if len (sig .parameters ) > 0 :
@@ -185,7 +185,7 @@ def main():
185
185
else :
186
186
command ()
187
187
else :
188
- print (f"Command { command } not found in the controller." )
188
+ print (f"Command { action } not found in the controller." )
189
189
190
190
import doctest
191
191
doctest .testmod ()
0 commit comments