2008-03-07 21:02:58 -05:00
|
|
|
USING: help.markup help.syntax kernel words ;
|
2008-04-01 17:51:48 -04:00
|
|
|
IN: classes.singleton
|
2008-03-05 22:35:08 -05:00
|
|
|
|
2008-04-02 17:32:34 -04:00
|
|
|
ARTICLE: "singletons" "Singleton classes"
|
2008-04-03 22:19:20 -04:00
|
|
|
"A singleton is a class with only one instance and with no state."
|
2008-04-02 17:32:34 -04:00
|
|
|
{ $subsection POSTPONE: SINGLETON: }
|
2008-04-03 22:19:20 -04:00
|
|
|
{ $subsection define-singleton-class }
|
|
|
|
"The set of all singleton classes is itself a class:"
|
|
|
|
{ $subsection singleton-class? }
|
|
|
|
{ $subsection singleton-class } ;
|
2008-04-02 17:32:34 -04:00
|
|
|
|
2008-03-05 22:35:08 -05:00
|
|
|
HELP: SINGLETON:
|
2008-04-03 22:19:20 -04:00
|
|
|
{ $syntax "SINGLETON: class" }
|
|
|
|
{ $values
|
2008-03-07 21:02:58 -05:00
|
|
|
{ "class" "a new singleton to define" }
|
2008-04-03 22:19:20 -04:00
|
|
|
}
|
|
|
|
{ $description
|
|
|
|
"Defines a new singleton class. The class word itself is the sole instance of the singleton class."
|
|
|
|
}
|
|
|
|
{ $examples
|
2008-04-26 03:01:06 -04:00
|
|
|
{ $example "USING: classes.singleton kernel io ;" "IN: scratchpad" "SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
|
2008-03-05 22:35:08 -05:00
|
|
|
} ;
|
2008-04-02 17:32:34 -04:00
|
|
|
|
|
|
|
HELP: define-singleton-class
|
|
|
|
{ $values { "word" "a new word" } }
|
|
|
|
{ $description
|
2008-04-03 22:19:20 -04:00
|
|
|
"Defines a singleton class. This is the run-time equivalent of " { $link POSTPONE: SINGLETON: } "." } ;
|
2008-04-02 17:32:34 -04:00
|
|
|
|
|
|
|
{ POSTPONE: SINGLETON: define-singleton-class } related-words
|
|
|
|
|
2008-04-03 22:19:20 -04:00
|
|
|
HELP: singleton-class
|
|
|
|
{ $class-description "The class of singleton classes." } ;
|
|
|
|
|
2008-04-02 17:32:34 -04:00
|
|
|
ABOUT: "singletons"
|