diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2018-07-06 13:50:54 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2018-07-06 13:50:54 (GMT) |
commit | 026619c58bc4283b4b67d859ee2628cd0f041ac3 (patch) | |
tree | edea7e82d38a056697016644cde74a2afaaaf853 /doc/singleton.n | |
parent | 948f2a216a04d9c6b43388c235b30d8b982aa9d0 (diff) | |
download | tcl-026619c58bc4283b4b67d859ee2628cd0f041ac3.zip tcl-026619c58bc4283b4b67d859ee2628cd0f041ac3.tar.gz tcl-026619c58bc4283b4b67d859ee2628cd0f041ac3.tar.bz2 |
Improving the singleton
Diffstat (limited to 'doc/singleton.n')
-rw-r--r-- | doc/singleton.n | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/doc/singleton.n b/doc/singleton.n index 6319abe..568a8bd 100644 --- a/doc/singleton.n +++ b/doc/singleton.n @@ -32,16 +32,20 @@ not recommended to inherit from a singleton class; singleton-ness is \fInot\fR inherited. It is not recommended that a singleton class's constructor take any arguments. .PP -Instances have their\fB destroy\fR method (from \fBoo::object\fR) unexported -in order to discourage destruction of the object, but destruction remains -possible if strictly necessary (e.g., by destroying the class or using -\fBrename\fR to delete it). +Instances have their\fB destroy\fR method overridden with a method that always +returns an error in order to discourage destruction of the object, but +destruction remains possible if strictly necessary (e.g., by destroying the +class or using \fBrename\fR to delete it). They also have a (non-exported) +\fB<cloned>\fR method defined on them that similarly always returns errors to +make attempts to use the singleton instance with \fBoo::copy\fR fail. .SS CONSTRUCTOR The \fBoo::singleton\fR class does not define an explicit constructor; this means that it is effectively the same as the constructor of the \fBoo::class\fR class. .SS DESTRUCTOR -The \fBoo::singleton\fR class does not define an explicit destructor. +The \fBoo::singleton\fR class does not define an explicit destructor; +destroying an instance of it is just like destroying an ordinary class (and +will destroy the singleton object). .SS "EXPORTED METHODS" .TP \fIcls \fBnew \fR?\fIarg ...\fR? @@ -53,11 +57,13 @@ manufactured; that construction is via the \fBoo::class\fR class's \fBnew\fR method. .RS .PP -This is an override of the behaviour of a superclass's method. +This is an override of the behaviour of a superclass's method with an +identical call signature to the superclass's implementation. .RE .SS "NON-EXPORTED METHODS" The \fBoo::singleton\fR class explicitly states that \fBcreate\fR and -\fBcreateWithNamespace\fR are unexported. +\fBcreateWithNamespace\fR are unexported; callers should not assume that they +have control over either the name or the namespace name of the singleton instance. .SH EXAMPLE .PP This example demonstrates that there is only one instance even though the |