No, you shouldn't :-)<br>But this is a well-known problem in meta-programming<br><br>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)<br><br>A better example is the concept of an abstract class, with concrete subclasses:<br>A is an abstract class, so 'A class>>new' raises an error (like with a singleton)
<br>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.<br>So it is not always conceptually right for classes and their metaclasses to inherit in parallel.<br><br>This paper explains the problem clearly and proposes a solution which uses code (and class) generation
<br>Safe Metaclass Programming (1998) ( Noury M.N. Bouraqadi-Saâdani, Thomas Ledoux, Fred Rivard)<br><a href="http://citeseer.ist.psu.edu/37617.html">http://citeseer.ist.psu.edu/37617.html</a><br><br>This paper uses traits for metaclass programming
<br>Uniform and safe metaclass composition (Stéphane Ducasse, Nathanael Schärli, Roel Wuyts)<br><a href="http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf">http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf
</a><br><br><br>(sorry if I have told incorrect things, I'm actually quite new to all this :-) )<br><br>On 12/3/05, Philippe Marschall <<a href="mailto:philippe.marschall@gmail.com">philippe.marschall@gmail.com</a>> wrote:
<br>> > There's no need for a seperate class to handle this.<br>> <br>> I disagree. Should I really have to duplicate this code every time I<br>> want a new singleton class?<br>> <br>> <br><br>