design mode, MVC Model View Controller mode (8)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.