On 8/25/06, Trey Harris <[EMAIL PROTECTED]> wrote:
> subclasses can remove functionality as well as adding it

Can someone suggest some reading I can do to understand how that works?
I can't wrap my head around the idea of subclasses removing functionality.

Why not?  Is it any weirder than simply changing that functionality
beyond recognition?

You can always fake removing functionality even if the language
doesn't actually support it.  Consider:

class Super { method something {...} }

class Sub is Super { method something { throw new MissingMethodException; } }

or whatever that ends up looking like.

In Ruby and C++, a subclass can make a method private that is public
in its superclass, effectively removing it.  (Java disallows such
shenanigans).

Does this mean you can't write

   class Super { method something { ... } }

   sub foo (Super $bar) { $bar.something() }

and expect foo($obj) to work

Of course you can expect foo($obj) to work.  It might not, if the
subclass definition does something weird, but that's always the case
whether "removing functionality" is on the table or not, and it's no
reason to change your reasonable expectations. You can be paranoid
about it if you want, but it's not a very Perlish form of paranoia.
(Yes, there are Perlish forms of paranoia.  Taintedness checking, for
instance...)

--
Mark J. Reed <[EMAIL PROTECTED]>

Reply via email to