zoukankan      html  css  js  c++  java
  • pureMvc(一)

    原文地址:

    http://puremvc.org/component/option,com_wrapper/Itemid,183/

    http://wiki.9ria.com/PureMVC

    (1)源码之Core层

    Model:Model类用于保存对Proxy对象的引用,并通过Proxy来操作数据模型,与远程服务通信存取数据。

        Model类中有一个proxyMap数组,这个数组通过关联数组的方式来存储Proxy实例,在实现IModel接口的方法中,通过处理这个数组来管理Proxy实例对象


    View:View保存了对Mediator对象的引用,并通过Mediator对象来操作具体的视图组件(这些操作包括添加事件监听器、发送或接收Notification、直接改变视图组件的状态)。

        主要作用:管理Mediator和处理消息。

        View中有保存了两个数组:mediatorMap(保存Madiator名与Mediator对象的映射)和observerMap(保存Observer名与Observer对象列表的映射:注意,这是列表),

                    当然因为Observer列表是与Mediator相关的,所以在处理Mediator对象时,也相应滴处理了相关的Observer列表。

    Controller:Controller保存所有的Command的映射。

         Controller保存一个数组commandMap,该数组用于保存Notification名与Command类引用的映射。

         这里需要注意的是Command类是无状态的,只有在需要时才被创建。Command可以获取Proxy对象并与之交互,发送Notification,执行其他的Command。



    (2)pureMvc通信

    1、PureMVC的通信主要依靠三个类来实现:ObserverNotiticationNotifier。(org.puremvc.patterns.observer

      Observer处理notification方法和上下文,并提供notify方法;

      Notification保存信息的对象名称、类型及传递的信息内容,并且提供了相应的getter/setter;

      Notifier发送信息,所以只提供了一个sendNotification()方法用于发送信息。

    2、对于MVC中的MediatorProxyCommand三个类而言,Mediator对象可以发送、声明、接收NotificationProxy只发送,不接收Notification

    3、当用View注册Mediator时,MediatorlistNotifications方法会被调用,以数组形式返回该Mediator对象所关心的所有Notification

      之后,当系统其它角色发出同名的Notification(通知)时,关心这个通知的Mediator都会调用handleNotification方法并将Notification以参数传递到方法。

    4、在很多场合下Proxy需要发送Notification(通知),比如:Proxy从远程服务接收到数据时,发送Notification告诉系统;或当Proxy的数据被更新时,发送Notification告诉系统。

      如果让Proxy也侦听Notification(通知)会导致它和View(视图)层、Controller(控制)层的耦合度太高。

      ViewController必须监听Proxy发送的Notification,因为它们的职责是通过可视化的界面使用户能与Proxy持有的数据交互。

    (3)PureMVC之Facade

      PureMVC应用了Façade模式。Façade是Model, View, Controller三者的经纪人。

      实际的应用程序都有一个Façade子类,这个Façade类对象负责初始化Controller,建立CommandNotification名之间的映射,并执行一个Command注册所有的ModelView

  • 相关阅读:
    Native Boot 从一个 VHD 引导系统的相关说明
    bind()函数的深入理解及两种兼容方法分析
    四、CentOS 6.5 上传和安装Nginx
    jQuery 常见操作实现方式
    “贷券” 信贷系统
    注册 Ironic 裸金属节点并部署裸金属实例
    hover()方法
    Uncaught SyntaxError: Inline Babel script: Unexpected token
    Uncaught Error: The `style` prop expects a mapping from style properties to values, not a string
    jquery bind事件
  • 原文地址:https://www.cnblogs.com/xiaowai/p/2342717.html
Copyright © 2011-2022 走看看