zoukankan      html  css  js  c++  java
  • Cairngorm的command并不是一直存在,而是触发一次就创建一次command类的实例

    注册的每个command类都存放到了一个Dictionary里面,每次需要用到的时候都是实例化了一次。这是cairngorm旧版本里的代码:

    private var commands : Dictionary = new Dictionary();
    
     public function addCommand( commandName : String, commandRef : Class ) : void
          {
             if( commands[ commandName ] != null )
             {
                throw new CairngormError(
                   CairngormMessageCodes.COMMAND_ALREADY_REGISTERED, commandName );
             }
             
             commands[ commandName ] = commandRef;
             CairngormEventDispatcher.getInstance().addEventListener( commandName, executeCommand );
          }
          
          protected function executeCommand( event : CairngormEvent ) : void
          {
             var commandToInitialise : Class = getCommand( event.type );
             var commandToExecute : ICommand = new commandToInitialise();
    
             commandToExecute.execute( event );
          }
          
          /**
           * Returns the command class registered with the command name. 
           */
          protected function getCommand( commandName : String ) : Class
          {
             var command : Class = commands[ commandName ];
             
             if ( command == null )
             {
                throw new CairngormError(
                   CairngormMessageCodes.COMMAND_NOT_FOUND, commandName );
             } 
                
             return command;
          }   
    

  • 相关阅读:
    l1-013
    将博客搬至CSDN
    Educational Codeforces Round 25
    大组合数取余模板【Lucas定理】
    Exams(二分求左界+贪心)
    Cutting (暴力 + 滚动哈希判字符串匹配)
    Cubes(DFS+剪枝)
    Codeforces Round #409 (Div. 2)
    【复习挖坑】dp + 图
    n & n-1 和 n & -n
  • 原文地址:https://www.cnblogs.com/JD85/p/1956682.html
Copyright © 2011-2022 走看看