Perl Monk, Perl Meditation | |
PerlMonks |
Re: Generic object in inside-out classesby stvn (Monsignor) |
on Feb 11, 2007 at 15:27 UTC ( [id://599466]=note: print w/replies, xml ) | Need Help?? |
I think this has interesting possibilities for describing inside-out singletons, but it blurs the lines between class and instance-of-the-class a little too much IMO. This is similar actually to the Perl 6 concept of the prototypical object, where a variable which is typed as a certain class has access to that class's methods without being officially blessed into that class. This makes things like this possible. The Foo::new method here is invoked on the $foo variable, which is (as @Larry describes it) "Foo but undef" which means that the variable will evaluate to undef in the right context, but act as the class Foo other contexts. However, your example does differ in that the Perl 6 version of the Foo class itself doesn't become an active instance as it would seem to do in your example. This also reminds me of metaclasses in a way. In most metaclass systems, a metaclass is an instance of the class "Class" and is responsible for facilitating the creation of instances of the class it descibes. Because each class is then essentially a metaclass instance, it is possible to store class data and methods as instance data and methods of the metaclass instance itself (of course a little syntactic sugar is usually required to make this seem more natural). But again, your example does differ from metaclasses in that the instance of a metaclass is not the same as an instance of the class it describes, so it cannot respond to the same methods or store the same data as the class.
-stvn
In Section
Meditations
|
|