Hands-On Enterprise Application Development with Python
上QQ阅读APP看书,第一时间看更新

Model

The model is the place where the business logic of the application lives. Many a time, developers confuse a model with a database, which may be true for some web applications, but is otherwise not if considered in general.

The role of the model is to deal with the data, provide access to it, and allow for modifications as they are requested. This includes retrieving data from the database or filesystem, adding new data to it, and modifying the existing data when updates are required.

A model is not concerned with how the data stored should be presented to the user or another component of the application, and hence decouples the presentation logic from the business logic. The model also doesn't change its schema frequently, and is more or less consistent throughout the application life cycle.

So, in brief, the model is responsible for performing the following roles:

  • Provide methods to access the data stored in the application
  • Decouple the presentation logic from business logic
  • Provide persistence to the data being stored in the application
  • Provide a consistent interface to deal with the data