in reply to Inheritance and objects tied to a database

Personally I feel it would be cleaner not to tie the hash representing the object (be it parent or child), but rather to an attribute such as $self->{data}, that way it's an attribute that has to be untied rather than the "object" itself.

Just my 2 cents, -gjb-

Replies are listed 'Best First'.
Re: Re: Inheritance and objects tied to a database
by relax99 (Monk) on Dec 20, 2002 at 12:45 UTC
    I agree. It does look cleaner, but how would that help?

      Since the child is initialized with the attribute values of the parents, it "inherits" a reference to the tied variable, so parent and child share the same data. Untieing one is untieing the other.

      Hope this helps, -gjb-

        So that would involve untieing the $self->{data} in the child class, but NOT untieing it in the parent class? That's the only way I imagine it would work, but I don't know how to do that (how to prevent calling the parent's DESTROY() method. If both parent's and child's DESTROY() methods are called, the parent's DESTROY() method still overwrited the tied data with its copy as opposed to updated child's data.

        Maybe I'm just trying to do something that doesn't really have to be done. I just want to know if I'm going all wrong about the whole thing.