@@ -63,12 +63,12 @@ def show_item_information(self, item_type: str, item_name: str, item_info: str)
6363 pass
6464
6565 @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 :
6767 pass
6868
6969
7070class 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 :
7272 print (item_type .upper () + " LIST:" )
7373 for item in item_list :
7474 print (item )
@@ -86,21 +86,21 @@ def show_item_information(self, item_type, item_name, item_info) -> None:
8686 printout += "\n "
8787 print (printout )
8888
89- def item_not_found (self , item_type , item_name ) -> None :
89+ def item_not_found (self , item_type : str , item_name : str ) -> None :
9090 print (f'That { item_type } "{ item_name } " does not exist in the records' )
9191
9292
9393class 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
9797
9898 def show_items (self ) -> None :
9999 items = list (self .model )
100100 item_type = self .model .item_type
101101 self .view .show_item_list (item_type , items )
102102
103- def show_item_information (self , item_name ) -> None :
103+ def show_item_information (self , item_name : str ) -> None :
104104 """
105105 Show information about a {item_type} item.
106106 :param str item_name: the name of the {item_type} item to show information about
@@ -119,15 +119,15 @@ class Router:
119119 def __init__ (self ):
120120 self .routes : dict = {}
121121
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 )
126126
127- def resolve (self , path ) -> Controller :
127+ def resolve (self , path : str ) -> Controller :
128128 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
131131 else :
132132 return None
133133
@@ -170,11 +170,11 @@ def main():
170170 router .register ("products" , Controller , ProductModel , ConsoleView )
171171 controller : object = router .resolve (argv [1 ])
172172
173- command : str = str (argv [2 ]) if len (argv ) > 2 else ""
173+ action : str = str (argv [2 ]) if len (argv ) > 2 else ""
174174 args : str = ' ' .join (map (str , argv [3 :])) if len (argv ) > 3 else ""
175175
176- if hasattr (controller , command ):
177- command = getattr (controller , command )
176+ if hasattr (controller , action ):
177+ command = getattr (controller , action )
178178 sig = signature (command )
179179
180180 if len (sig .parameters ) > 0 :
@@ -185,7 +185,7 @@ def main():
185185 else :
186186 command ()
187187 else :
188- print (f"Command { command } not found in the controller." )
188+ print (f"Command { action } not found in the controller." )
189189
190190 import doctest
191191 doctest .testmod ()
0 commit comments