Singleton
Intent
Ensure a class only has one instance, and provide a global point of access to it.
Class diagram of the original GoF pattern

Another solution in MixJuice
Solved Problem(s)
- Complexity problem
- The original GoF pattern is complicated and error prone. (Although this problem is not mentioned in the GoF book, the demerits of static methods are mentioned at p.128, line.14-16 that implies static methods are preferable if these demerits do not matter.)
Used programming technique(s)
Method extension of static methods solve the problem of static methods, limitation of extensibility. (Note that the current version of MixJuice, version 1.0, does not support method extension of static methods; however the future version will support it.)
Consequences
- (+) Source code becomes simple and straightforward.
- (-) As mentioned at p.128, line.26-31 in the GoF book, it is hard to change a design to allow more than one instance of a class.
Structure and pseudo code

module original {
define class C {
define static void operation() {...}
define static int data;
}
}
module extension extends original {
class C {
static void operation() { ... original() ...}
}
}
Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>Top