Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Introducing Class::InsideOut

by adrianh (Chancellor)
on Feb 14, 2006 at 15:56 UTC ( [id://530150]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Introducing Class::InsideOut
in thread Introducing Class::InsideOut

However, I think I would go so far and enforce the separation of creation and initialization. As a designer, it gives you one more point of control (->new is your baby now). Your users fully control object construction through their ->init methods.

But if you're providing your own new you lose the ability to subclass other classes that are not based on your system. An extremely nice feature of Class::InsideOut IMO.

Replies are listed 'Best First'.
Re^5: Introducing Class::InsideOut
by Anno (Deacon) on Feb 15, 2006 at 09:46 UTC

    Why? The common new can support it:

    sub new { my $class = shift; bless @_ ? shift : \ my $x, $class; }

    That way you can use an arbitrary foreign object as the donator of the new id.

    Anno

      Sorry - I fail to see how this helps in subclassing an pre-existing class. What you seem to be doing here is taking an existing object and re-blessing it into your new class - which will break inheritance, method resolution, etc.

        It will work as long as the @ISA gets set up correctly. It's no different than what Class::InsideOut does to support inside-out objects. All anno's solution does is provide a default constructor that can take a foreign object.

        That said, I'm not sure where it really helps as his solution still either requires an overridding new to add an initialization call or else will provide an explicit call to an init or BUILD. The former approach doesn't really save any code and the latter approach is another straightjacket -- however comfy. Put differently, his new just makes it easier to generate either an anonymous scalar or to rebless an existing object.

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found