Keep It Simple, Stupid | |
PerlMonks |
Re: Re: Class::Interface -- isa() Considered Harmfulby chromatic (Archbishop) |
on Jan 17, 2003 at 17:28 UTC ( [id://227747]=note: print w/replies, xml ) | Need Help?? |
It was an unclear example. I hesitate to use this example, knowing that the likely response will be "Tying won't work that way in Perl 6." To forestall those replies, I know that this is the case. I'm also not interested in questions of "Why are you doing this anyway?" This is an example of the shortcomings of relying on inheritance. I can come up with clever hacks to get around all this, but I would rather that I not have to do so. If you do have a better solution that achives both of my goals (it should be possible to check that things can handle the operations I'm about to perform on them, and this check should not dictate the implementation of these operations), I'm all ears. Consider a constructor:
If $args doesn't exist, the two dereferences will fail. We can check for that:
If $args isn't a reference to a hash, the two dereferences will fail. Here's where it gets tricky:
That looks fine, and I was happy to use it until I realized it would break if someone passed in a tied hash. Since neither Tie::Hash or Tie::StdHash inherit from HASH, this will fail if I use a tied hash. There are several possibilities:
I much prefer a system that lets me ask one question: am I dealing with something that acts according to this named set of behaviors?
In Section
Meditations
|
|