zoukankan      html  css  js  c++  java
  • MVC-MODEL

    http://www.gameres.com/thread_484046_1_1.html

    MVC从施乐帕克实验室提出至今,已经应用到各种应用开发领域中:Web App可以用MVC,iOS/Android/Windows客户端应用也用MVC,Web 前端也在用MVC,等等;这些几乎涵盖了我们常见的开发领域,所以MVC其实已经超越了他原本最初的设计,基于所有涉及展示的应用都 能套上MVC,只不过不同的平台在设计上略有差别。而MVP和MVVM,也不过是MVC的衍生变种,除这两者之外,还有我们没怎么见过的HMVC 、MVA等。

      4.2 Model Layer

      在讨论MVP和MVVM之前,我想先明确一个经常被误解的概念:Model。由于Model这个词太通用化,如数据Model,数据库Model,这就导致 了Model这一概念理解差异化,简单的说,就是被玩坏。抛开其他,我们来看看常见的定义:

      Wikipedia的定义:

    1. The central component of MVC, the model, captures the behavior of the application in terms of its problem domain, independent of the user interface.[11] The model directly manages the data, logic and rules of the application.
    复制代码


      MSDN(https://msdn.microsoft.com/en-us/library/ff649643.aspx)中的定义:

    1. Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).
    复制代码


      上面两个定义基本一致:Model,管理应用的行为和数据。

      再来看看Apple官方文档Model-View-Controller的定义:

    1. Model Objects
    2. Model objects encapsulate the data specific to an application and define the logic and computation that manipulate and process that data. For example, a model object might represent a character in a game or a contact in an address book. A model object can have to-one and to-many relationships with other model objects, and so sometimes the model layer of an application effectively is one or more object graphs. Much of the data that is part of the persistent state of the application (whether that persistent state is stored in files or databases) should reside in the model objects after the data is loaded into the application. Because model objects represent knowledge and expertise related to a specific problem domain, they can be reused in similar problem domains. Ideally, a model object should have no explicit connection to the view objects that present its data and allow users to edit that data—it should not be concerned with user-interface and presentation issues.
    3. Communication: User actions in the view layer that create or modify data are communicated through a controller object and result in the creation or updating of a model object. When a model object changes (for example, new data is received over a network connection), it notifies a controller object, which updates the appropriate view objects.
    复制代码


      虽然Apple的官方文档是定义Model Objects,但它的含义还是封装数据以及管理数据相关的逻辑计算;

      所以这里需要明确的一个概念是:在MVC的设计模式中,Model是一个Layer,而不只是一个数据模型(Data Model)类。总体来说, Model Layer 包含了数据模型,以及管理这些数据相关的逻辑计算,如本地数据变化、数据缓存、从网络请求数据等业务逻辑。关于这 个问题,还可以参考这篇文章:《iOS应用架构谈 view层的组织和调用方案》。但有一点需要说明:该文章更倾向于从Model Object上 思考Model的定义,因为里面的关于Model的示例是从数据模型中扩展出业务接口;而本人则更倾向于从Model Layer来思考Model,即 Model并不限于数据模型,可以是数据管理类(各种Manager)、请求队列管理等等。

  • 相关阅读:
    查找算法(I) 顺序查找 二分查找 索引查找
    快速排序 Quick Sort
    Activity生命周期
    Android中资源文件的使用
    排序算法
    插入排序(I)Insert Sort
    Java eclipse调试技巧什么的。。
    HTTP协议解析
    python技巧26[str+unicode+codecs]
    python类库26[PySide之helloworld]
  • 原文地址:https://www.cnblogs.com/feng9exe/p/7339559.html
Copyright © 2011-2022 走看看