in reply to Re^5: Re-blessing || Re-constructing objects
in thread Re-blessing || Re-constructing objects

Then I'd ask why you wrote this code as OO, since you aren't getting a major benefit of OO: abstraction.

Because I want to take advantage of another benefit of OO - polymorphism?

There are many common approaches for doing the kind of thing you describe that don't require breaking encapsulation.

Yup. But sometimes adding that extra layer of indirection makes things harder to understand rather than simpler, and sometimes breaking encapsulation of implementation doesn't hurt anybody.

I agree that reblessing is usually a sign of a design gone wrong - but sometimes it is the simplest solution. And that's fine with me as long as it doesn't get in the way elsewhere.

  • Comment on Re^6: Re-blessing || Re-constructing objects

Replies are listed 'Best First'.
Re^7: Re-blessing || Re-constructing objects
by perrin (Chancellor) on Apr 18, 2006 at 14:26 UTC
    The person trying to debug this code later may not agree that doing something so strange and unexpected just to save a few lines was worth it.
      The person trying to debug this code later may not agree that doing something so strange and unexpected just to save a few lines was worth it.

      Possibly. But the very few occasions I have used the technique the motivation hasn't been to save lines of code. It's been to provide a simpler and clearer solution than the alternatives. I can only hope I succeeded.