源自《cocoa设计模式》
The Role of the Model Subsystem Consider the role of the Model subsystem in a ModelView Controller application.The model is composed of the objects that provide the unique capabilities and information storage for an application. Models contain the rules for processing application data. Mod- els provide the in-memory representation of application data to be viewed, edited, or processed.
Models are also usually responsible for persistent storage of application data.The model must load or store data in some way. Common forms of persistent storage include files on a disk drive, client-server databases, and more recently,“cloud” computing where data is stored on an anonymous remote server and accessed using Universal Resource Lo- cators (URLs).
Some models need to work with vast amounts of data, and it’s not practical to keep all of the data in memory at once. In such cases, models sometimes include search features or filters to limit the amount of data in memory at one time.
Models contain the logic or rules for manipulating data. Some data may be calculated from other data using application-specific algorithms. Data may be constrained to specific types like “dates” or “positive integers.” Data values may have defined minimums and maximums. Models provide data validation to ensure that constraints are met.
Models manage relationships between objects. For example, a model that stores infor- mation about books and publishers might contain the following rules: “each publisher has a list of zero or more books that have been published,”“each book has zero or one identified publisher,” and “whenever a book is added to a publisher’s list of published books, the book’s identified publisher must be set to correspond.”