On 6/1/06, Joost D. firstname.lastname@example.org wrote:
inheriting from your base classes too, and I cann’t think of any language
needed behavior. Any external object will still be not able to call
these methods. So they are providing a way to customize your internal
implementation when working with hierarchies, but not offer it as an
My argument was that you then have to disallow people from implementing
their own classes based on your classes, because if they do, they still
can call the protected methods you just worked so hard to “protect”.
But I haven’t worked on protecting them against overridding, but
against direct calls. Big difference.
My main point though, is that if you think you need protected methods you
should think really hard about wether other classes might find those
methods useful too (i.e. just make them public instead).
This is a matter of the API designer skills. However making everything
public, for the sake that somebody may find one of the methods usefull
is imo worse than having to evolve your initial API.
I’ve ran into too many problems with libraries where you just can’t call
very handy methods because the designer decided you shouldn’t and then it
takes hours to work around that. My gut feeling is that protected methods
are usually either badly designed, or made so the designer can feel good
about not binding the API to the implementation. If your implementation is
so bad you don’t want other people relying on it, but you still need
access to it to make your code work, you’re doing something wrong.
It’s sad to hear this, but unfortunately I would say that it was your
bad luck to work with bad designed APIs. Agreed, some projects get it
right from the 1st version, other are learning how to do it.
.w( the_mindstorm )p.
PS: probably we just have to agree to disagree :-). For me protected
is usefull and has been. Bad APIs is another topic and in some of the
companies I have worked for there were specific people for designing
the APIs for the frameworks used by hundred of other developers (I was
one of them and frankly speaking, so far, I haven’t had such a
bad feedback as you describe).