in reply to Re^3: Inheritance problem: Not a HASH ref
in thread Inheritance problem: Not a HASH ref

Breaks encapsulation

I have been regurgitating this for awhile and I wonder if it isn't too extreme. In the sense of "since when inheritance breaks encapsulation?"

  • Comment on Re^4: Inheritance problem: Not a HASH ref

Replies are listed 'Best First'.
Re^5: Inheritance problem: Not a HASH ref
by tobyink (Canon) on Feb 26, 2019 at 17:08 UTC
      Child classes shouldn't rely on private implementation details of their superclass.

      Fine tobyink, clear and acceptable. Albeit (I am talking in general and not for some module mentioned here), a hint in the pod a la "do not subclass me, I don't like to play ball this way" would have gone further than trying to obscure. My opinion, for what is worth, is that if you write OOP then play OOP. Exhibhit your private parts but with ample of warnings not to be touched and allow for some kind of subclassing for some of your public functioning so as to move the state-of-the-art a click forward.

      bw, bliako

        do not subclass me, I don't like to play ball this way

        Just because it isn't a hash that doesn't mean you can't inherit from it. It's just implemented in a way that makes using the more traditional way of implementing objects not work. "OOP" has little to do with hashes IMO.

        Subclassing of Furl is still easy. You can easily write a subclass My::Furl that overrides methods on it. What is hard is attaching additional information to the object. You've been shown various ways on how to associate information with the objects.

        I don't think any class should indicate that they shouldn't be subclassed. It should always be possible to subclass classes. (Java's final keyword allows you to create classes like this, and it's dumb.)

        Subclasses should only use the documented API of their parent class, but it should always be possible to subclass any class, and authors of classes should try to be as kind as possible to subclassers.