zoukankan      html  css  js  c++  java
  • AX单例模式

    有MVC开发经历的童鞋,可能发现X++由于不支持静态变量是不支持单例模式,Form之间传值只能通过Args类传递。这样程序开发的灵活性就大大受到限制。

    有人发现,通过系统全局缓存机制来实现单例模式。

     1 public static SingletonClass getInstance()
     2 {
     3     SingletonClass instance;
     4     SysGlobalCache globalCache = infolog.objectOnServer() ? appl.globalCache() : infolog.globalCache();
     5     ;
     6 
     7     if (globalCache.isSet(classStr(SingletonClass), 0))
     8         instance = globalCache.get(classStr(SingletonClass), 0);
     9     else
    10     {
    11         instance = new SingletonClass();
    12         infoLog.globalCache().set(classStr(SingletonClass), 0, instance);
    13         appl.globalCache().set(classStr(SingletonClass), 0, instance);
    14     }
    15 
    16     return instance;
    17 }

    SingletonClass这个类的实例被存储在SysGlobalCache类型的对象globalCache中,它将一直被保存在缓存中直到系统被关闭。

  • 相关阅读:
    hdu 2132 An easy problem
    ACM暑假培训宣讲稿
    hdu Lovekey(水题)
    windows 下c++编译
    semantic
    could not open XXX permission denied
    sv_target_output dx11
    hlsl 的tex函数
    effect state dx11
    cg 到hlsl的转换
  • 原文地址:https://www.cnblogs.com/Jinnchu/p/2659603.html
Copyright © 2011-2022 走看看