Re-blessing objects is not cool nor evil. It's stupid. It's just asking for trouble, even when you know what you're doing. Why bother at all with "OO" if you're going to break the rules?

Ive done this quite a few times. I dont think its so bad depending on the purpose and requirements. For instance, I have a routine that returns a list of objects from a query that can perform a particular function. In fact the internals of those objects are quite complicated and expensive to fetch and more often than not I dont need to use all of the returned objects (but wont know if I do until too late), so I actually use two classes of objects. The first class has as its contents the required information to complete the building process. All of the accessor methods simply cause the object to complete the build, rebless, and then recall whatever it was that was originally called. That way I only need to do a full build on the objects I actually use. As a way of transparently encapsulating such behaviour I think reblessing is a fine way to procede. (I think in a way you could compare it to a "seed" object turning into a "Tree" object.)

Now there are times and places for everything. I wouldn't encourage a lot of reblessing, but I dont think it should be just automatically rejected. There are times where it makes perfect sense.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi



In reply to Re: Re: Re: inheritance and object creation by demerphq
in thread inheritance and object creation by knew

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.