zoukankan      html  css  js  c++  java
  • initial class tcl tk

    class Singleton {
           private common _instance {}  ;# static instance variable

           #
           # Define a "static method" Instance.
           #
           proc Instance {} {
               if { $_instance == {} } {
                 set _instance [Singleton ABC]
                  }
           return $_instance
           }
           # end of Instance
           constructor {} {
              set caller [info level [expr [info level] - 1]]
             if ![string match "Singleton::Instance" $caller] {
                   error "Class Singleton can not be directly instantiated - use Instance"
               }

          }

    }

    set s [Singleton::Instance]

    set bb [Singleton::Instance]

    ==============================================


    class Singleton {
           private common _instance {}  ;# static instance variable
           constructor {} {
        if { $_instance == {} } {
            set _instance onlyone
        } else {
            error "Class Singleton already instantiated"
        }
           }
       }

    Singleton ab                 (right)
    Singleton cd                 (wrong)

  • 相关阅读:
    创建文件夹 文件File操作方法
    C#WinForm4张纸牌窗体设计
    b/s结构和c/s结构
    sql 中 时间只显示日期
    视图
    js获取字符串的字节数
    触发器
    将xml字符串转换成dataset
    sql 集合查询 数据更新操作语句
    带有ANY(SOME)或ALL谓词的字查询
  • 原文地址:https://www.cnblogs.com/greencolor/p/2046843.html
Copyright © 2011-2022 走看看