Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Generic object in inside-out classes

by stvn (Monsignor)
on Feb 11, 2007 at 15:27 UTC ( [id://599466]=note: print w/replies, xml ) Need Help??


in reply to Generic object in inside-out classes

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.

my Foo $foo .= new();
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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://599466]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found