Gitlib Gitlib
首页
  • 分类
  • 标签
  • 归档
  • Golang开发实践万字总结
  • MySQL核心知识汇总
  • Redis实践总结
  • MQ实践万字总结
  • Docker数据持久化总结
  • Docker网络模式深度解读
  • 常用游戏反外挂技术总结
  • 读书笔记
  • 心情杂货
  • 行业杂谈
  • 友情链接
关于我
GitHub (opens new window)

Ravior

以梦为马,莫负韶华
首页
  • 分类
  • 标签
  • 归档
  • Golang开发实践万字总结
  • MySQL核心知识汇总
  • Redis实践总结
  • MQ实践万字总结
  • Docker数据持久化总结
  • Docker网络模式深度解读
  • 常用游戏反外挂技术总结
  • 读书笔记
  • 心情杂货
  • 行业杂谈
  • 友情链接
关于我
GitHub (opens new window)
  • PHP

  • Golang

  • Python

  • Javascript

    • PureMVC

      • PureMVC(JS版)源码解析:认识PureMVC
      • PureMVC(JS版)源码解析01:观察者模式解析
      • PureMVC(JS版)源码解析02:Notification类
      • PureMVC(JS版)源码解析03:Observer类
      • PureMVC(JS版)源码解析04:Notifier类
      • PureMVC(JS版)源码解析05:SimpleCommand类
        • SimpleCommand类
      • PureMVC(JS版)源码解析06:MacroCommand类
      • PureMVC(JS版)源码解析07:Mediator类
      • PureMVC(JS版)源码解析08:Proxy类
      • PureMVC(JS版)源码解析09:View类
      • PureMVC(JS版)源码解析10:Controller类
      • PureMVC(JS版)源码解析11:Model类
      • PureMVC(JS版)源码解析12:Facade类
      • PureMVC(JS版)源码解析:总结
    • 从一个基础Javascript面试题谈起
    • Javascript垃圾回收机制
    • Javascript实现双向数据绑定
    • 浏览器渲染网页过程
    • 浏览器资源缓存机制总结
  • 其他语言

  • 编程语言
  • Javascript
  • PureMVC
Ravior
2013-10-07
目录

PureMVC(JS版)源码解析05:SimpleCommand类

PureMVC

之前对PureMVC中涉及到观察者模式的三个基本类(Notification/Observer/Notifier)进行了分析,接下来将对PureMVC源码中的其他类进行分析。

# SimpleCommand类

SimpleCommand在MVC类中属于C部分,用于一些复杂的逻辑处理,SimpleCommand类在PureMVC被设计成了一个双面角色,它既可以扮演通知者(Notifier)的角色(即可以发送Notification),也可以扮演观察者(Observer)接受消息。

通过分析源码可知,SimpleCommand类,继承了Notifier类:

function SimpleCommand () { };

SimpleCommand.prototype= new Notifier;
SimpleCommand.prototype.constructor= SimpleCommand;

1
2
3
4
5

由于继承了Notifier类,SimpleCommand类继承了Notifier类的sendNotification()方法,故说它可以扮演通知者角色。

另外,通过源码发现,SimpleCommand类,还有个execute()方法:

/**
 * Fulfill the use-case initiated by the given Notification
 * 
 * In the Command Pattern, an application use-case typically begins with some
 * user action, which results in a Notification is handled by the business logic
 * in the #execute method of a command.
 * 
 * @param {puremvc.Notification} notification
 *  The notification to handle.
 * @return {void}
 */
SimpleCommand.prototype.execute= function (notification) { };

1
2
3
4
5
6
7
8
9
10
11
12
13

execute()方法,接受一个Notifcation对象作为参数,但是至于何时会调用execute()方法暂时先不管他,记住SimpleCommand有这个方法。

因为execute()方法接受一个Notification对象作为参数,因此,SimpleCommand类可以接受消息。

SimpleCommand类的结构很简单,暂时只需要记住以下几点:

  • SimpleCommand类继承自Notifier类(作为消息通知者)
  • 有一个execute()方法,execute()方法接受一个Notification对象作为参数(作为消息接收者)
#PureMVC
上次更新: 2022/12/01, 11:09:34
PureMVC(JS版)源码解析04:Notifier类
PureMVC(JS版)源码解析06:MacroCommand类

← PureMVC(JS版)源码解析04:Notifier类 PureMVC(JS版)源码解析06:MacroCommand类→

最近更新
01
常用游戏反外挂技术总结
11-27
02
Golang开发实践万字总结
11-11
03
Redis万字总结
10-30
更多文章>
Theme by Vdoing | Copyright © 2011-2022 Ravior | 粤ICP备17060229号-3 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式