[Q] Why Squeak don't have a Singleton class ?

stijn timbermont stijn.timbermont at gmail.com
Sat Dec 3 12:04:20 UTC 2005


No, you shouldn't :-)
But this is a well-known problem in meta-programming

The reason why you cannot do this in smalltalk is because, when you have a
class A and a subclass B, the metaclass of B (being 'B class') must be a
subclass of the metaclass of A (being 'A class'). (The reason for this is to
guarantee upward and downward compatibility - see links below. In CLOS, one
is allowed to choose any metaclass in the class definition, but no
compatibility is guaranteed)

A better example is the concept of an abstract class, with concrete
subclasses:
A is an abstract class, so 'A class>>new' raises an error (like with a
singleton)
B is a subclass of A, inheriting all behaviour from A, and 'B class' (a
concrete class) is a subclass of 'A class': a concrete class inheriting its
behaviour from an abstract class.
So it is not always conceptually right for classes and their metaclasses to
inherit in parallel.

This paper explains the problem clearly and proposes a solution which uses
code (and class) generation
Safe Metaclass Programming (1998) ( Noury M.N. Bouraqadi-Saâdani, Thomas
Ledoux, Fred Rivard)
http://citeseer.ist.psu.edu/37617.html

This paper uses traits for metaclass programming
Uniform and safe metaclass composition (Stéphane Ducasse, Nathanael Schärli,
Roel Wuyts)
http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf


(sorry if I have told incorrect things, I'm actually quite new to all this
:-) )

On 12/3/05, Philippe Marschall <philippe.marschall at gmail.com> wrote:
> > There's no need for a seperate class to handle this.
>
> I disagree. Should I really have to duplicate this code every time I
> want a new singleton class?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20051203/d45a788d/attachment.htm


More information about the Squeak-dev mailing list