all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
21
Task/Singleton/Tcl/singleton-1.tcl
Normal file
21
Task/Singleton/Tcl/singleton-1.tcl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package require TclOO
|
||||
|
||||
# This is a metaclass, a class that defines the behavior of other classes
|
||||
oo::class create singleton {
|
||||
superclass oo::class
|
||||
variable object
|
||||
unexport create ;# Doesn't make sense to have named singletons
|
||||
method new args {
|
||||
if {![info exists object]} {
|
||||
set object [next {*}$args]
|
||||
}
|
||||
return $object
|
||||
}
|
||||
}
|
||||
|
||||
singleton create example {
|
||||
method counter {} {
|
||||
my variable count
|
||||
return [incr count]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue