[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.9 gauche.mop.singleton - Singleton

Module: gauche.mop.singleton
Provides a metaclass to define a singleton class.

Class: <singleton-meta>
Creates a singleton class. A singleton class is a class that is guaranteed to create only one instance. The first invocation of make creates the single instance, and further attempt of creation returns the same instance.

 
(define-class single () () :metaclass <singleton-meta>)

(define a (make single))
(define b (make single))

(eq? a b) => #t

The slots of the instance are initialized at the first invocation of make. Initargs of make are effective only in the fist invocation, and ignored in the subsequent invocation.

Method: instance-of (class <singleton-meta>) &rest initargs
This method just calls make with the passed arguments. It is more obvious in the program that you're dealing with singleton.

Class: <singleton-mixin>
An instance of <singleton-meta>. Instead of specifying <singleton-meta> as the :metaclass argument of define-class, you can inherit this class to give your class the property of singleton.



This document was generated by Ken Dickey on November, 28 2002 using texi2html