pureMVC理解

来源:互联网 发布:算法注册机免费下载 编辑:程序博客网 时间:2024/05/16 07:54

1.观察者模式:

pmvc的观察者模式同典型的观察者模式的不同之处是:

他的主体(subject,被观察者,通知者)具有统一的接口形式,他们都实现了INotifier接口;

INotifier

+sendNotification( notificationName, body, type);

观察者也具有统一的接口形式,他们都实现了IObserver接口;

IObserver

+notifyObserver( notification:INotification );


观察者模式中主体的通知行为时通过facade和view的间接传递来实现的,具体过程为

notifiier(proxy ,command 或者 mediator) -> facade -> view (通过查询observerMap)->observer-(最后执行的实体Mediator或者Controller)->(如果是controller则还要进一步查询commandMap实例化command)


所有的观察者都保存在view的observerMap中


2.注册

在注册Mediator时,view通过调用Mediator的listNotificationInterests()获取其所关心的通知类型,然后创建相应的观察者。

在注册Command时,Controller同时会调用view注册相应的观察者



原创粉丝点击