http://qs321.pair.com?node_id=375442


in reply to Re: Why is a hash the default "object" in oo perl?
in thread Why is a hash the default "object" in oo perl?

Heh ... thanks! Really what was bothering me was a statement I've read over and over in texts that deal with Object-Oriented programming (but not about using it in any particular language) which was:
A subclass shouldn't need to know anything about its parent's implementation, and the parent shouldn't need to know anything about a child's implementation

Or something along those lines. And while I was experimenting by trying to create a very generic "person" object (which could then become person::client, person::employee, person::vendor etc) I realized that I would end up violating both of those ideas by storing data inside a hash-ref as object

If I had been working on this for a paid project I would have just plowed forward as I'd be the one writting the subclasses anyway ...

However, since this was a learning experience, I was annoyed by the idea of 'cheating' and figured there had to be a way. I had once seen (here on perlmonks) using braces around a subroutine { $var; sub { ... }} to keep a variable alive between calls to the subroutine and used that in figuring out what I did.

I think after I read/learn Abigails implementation -- which I have no doubts is much more refined then my Saturday afternoon of hacking around -- I would likely use this as my default OO style.

theAcolyte

  • Comment on Re^2: Why is a hash the default "object" in oo perl?