The MVC pattern represents the Model-view-controller (model-View-controller) pattern. This pattern is used for tiered development of applications.
- Model-models represent an object or JAVA POJO that accesses data. It can also have logic to update the controller as the data changes.
- View-views represent the visualization of the data contained in the model.
- Controller-Controllers Act on models and views. It controls the flow of data to model objects and updates the view as the data changes. It leaves the view separated from the model.
Quotes = ('A man isn't complete until he's married. Then the he is finished.', 'as I said before, I never repeat myself.', 'Behind A successful man was an exhausted woman.', 'Black holes really suck ...','Facts is stubborn things.')classQuotemodel:defget_quote (self, n):Try: Value=Quotes[n]exceptIndexerror as Err:value='Not found!' returnvalueclassQuoteterminalview:defShow (self, quote):Print('And the quote is: "{}"'. Format (quote))deferror (Self, msg):Print('Error: {}'. Format (msg))defselect_quote (self):returnInput'which quote number would you like to see?')classQuoteterminalcontroller:def __init__(self): Self.model=Quotemodel () Self.view=Quoteterminalview ()defRun (self): Valid_input=False while notvalid_input:n=self.view.select_quote ()Try: N=int (n)exceptValueError as Err:self.view.error ("incorrect index ' {} '". Format (n))Else: Valid_input=True Quote=self.model.get_quote (n) self.view.show (quote)defMain (): Controller=Quoteterminalcontroller () whileTrue:controller.run ()if __name__=='__main__': Main ()
design mode, MVC Model View Controller mode (8)