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

In reply to Re: Generic object in inside-out classes by stvn
in thread Generic object in inside-out classes by Anno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.