1111
1212class Model (ABC ):
1313 """The Model is the data layer of the application."""
14+
1415 @abstractmethod
1516 def __iter__ (self ) -> Any :
1617 pass
@@ -29,6 +30,7 @@ def item_type(self) -> str:
2930
3031class ProductModel (Model ):
3132 """The Model is the data layer of the application."""
33+
3234 class Price (float ):
3335 """A polymorphic way to pass a float with a particular
3436 __str__ functionality."""
@@ -56,12 +58,15 @@ def get(self, product: str) -> dict:
5658
5759class View (ABC ):
5860 """The View is the presentation layer of the application."""
61+
5962 @abstractmethod
6063 def show_item_list (self , item_type : str , item_list : list ) -> None :
6164 pass
6265
6366 @abstractmethod
64- def show_item_information (self , item_type : str , item_name : str , item_info : dict ) -> None :
67+ def show_item_information (
68+ self , item_type : str , item_name : str , item_info : dict
69+ ) -> None :
6570 """Will look for item information by iterating over key,value pairs
6671 yielded by item_info.items()"""
6772 pass
@@ -73,6 +78,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
7378
7479class ConsoleView (View ):
7580 """The View is the presentation layer of the application."""
81+
7682 def show_item_list (self , item_type : str , item_list : list ) -> None :
7783 print (item_type .upper () + " LIST:" )
7884 for item in item_list :
@@ -84,7 +90,9 @@ def capitalizer(string: str) -> str:
8490 """Capitalizes the first letter of a string and lowercases the rest."""
8591 return string [0 ].upper () + string [1 :].lower ()
8692
87- def show_item_information (self , item_type : str , item_name : str , item_info : dict ) -> None :
93+ def show_item_information (
94+ self , item_type : str , item_name : str , item_info : dict
95+ ) -> None :
8896 """Will look for item information by iterating over key,value pairs"""
8997 print (item_type .upper () + " INFORMATION:" )
9098 printout = "Name: %s" % item_name
@@ -99,6 +107,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
99107
100108class Controller :
101109 """The Controller is the intermediary between the Model and the View."""
110+
102111 def __init__ (self , model_class : Model , view_class : View ) -> None :
103112 self .model : Model = model_class
104113 self .view : View = view_class
@@ -124,15 +133,17 @@ def show_item_information(self, item_name: str) -> None:
124133
125134class Router :
126135 """The Router is the entry point of the application."""
136+
127137 def __init__ (self ):
128138 self .routes = {}
129139
130140 def register (
131- self ,
132- path : str ,
133- controller_class : type [Controller ],
134- model_class : type [Model ],
135- view_class : type [View ]) -> None :
141+ self ,
142+ path : str ,
143+ controller_class : type [Controller ],
144+ model_class : type [Model ],
145+ view_class : type [View ],
146+ ) -> None :
136147 model_instance : Model = model_class ()
137148 view_instance : View = view_class ()
138149 self .routes [path ] = controller_class (model_instance , view_instance )
@@ -184,7 +195,7 @@ def main():
184195 controller : Controller = router .resolve (argv [1 ])
185196
186197 action : str = str (argv [2 ]) if len (argv ) > 2 else ""
187- args : str = ' ' .join (map (str , argv [3 :])) if len (argv ) > 3 else ""
198+ args : str = " " .join (map (str , argv [3 :])) if len (argv ) > 3 else ""
188199
189200 if hasattr (controller , action ):
190201 command = getattr (controller , action )
@@ -201,4 +212,5 @@ def main():
201212 print (f"Command { action } not found in the controller." )
202213
203214 import doctest
215+
204216 doctest .testmod ()
0 commit comments