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


          之前我们对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;

    由于继承了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) { };

    execute()方法,接受一个notifcation对象作为参数,但是至于何时会调用execute()方法我们现在还不清楚,先放着,记着SimpleCommand有这个方法。

    因为execute方法接受一个notification对象作为参数,因此,SimpleCommand类可以接受消息。 
     
    SimpleCommand类的结构很简单,我们暂时只需要记住SimpleCommand类继承自Notifier类,有一个execute方法,execute方法接受一个notification对象作为参数。
     
    最后,附上一张思维导图:
  • 相关阅读:
    CF Hello 2020 E.New Year and Castle Construction
    HTML 简介
    グランドエスケープ
    CF 1244 C
    N皇后解法以及位运算优化
    CF
    动态规划TG.lv(1) (洛谷提高历练地)
    搜索Ex (洛谷提高历练地)
    数字图像处理——图像增强
    数字图像处理——图像的几何变换
  • 原文地址:https://www.cnblogs.com/iRavior/p/3355579.html
Copyright © 2020-2023  润新知