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)

  • 相关阅读:
    java 简单封装resultMap返回对象为map
    freemarker 遍历树形菜单
    python 正则表达式
    python BeautifulSoup基本用法
    sublime中正则替换
    媒体查询
    响应式网站的优点和缺点
    响应式网站概念
    vue系列之vue-resource
    vue系列之项目打包以及优化(最新版)
  • 原文地址:https://www.cnblogs.com/greencolor/p/2046843.html
Copyright © 2011-2022 走看看