[Biojava-l] Private vs Protected
Simon Brocklehurst
simon.brocklehurst@CambridgeAntibody.com
Fri, 03 May 2002 11:39:24 +0100
David Waring wrote:
>
> I have found on several occasions that I would like to extend a class, but
> variables and methods are private so it is impossible to make use of these
> in the subclass. Is there a policy about when things should be kept private,
> and when they should be protected? Is it OK to change this in a base class
> when extending it?
>
David,
It might be a good idea to discuss the situation on this list when such
a situation occurs - the authors may have been following the "keep
things as private as possible" rule. That is, in some cases, there may
be no inherent design reason that some aspects of a class shouldn't be
made more public.
There is a view, however, that would say it's an "anti-pattern" to
extend classes in an API you don't have absolute control of. There are
obvious exceptions to this rule - for example, optimal patterns for
design of GUIs based on the JFC/Swing API include extending Swing
classes. Thus, it might also make sense to ask yourself whether
inheritance is *really* the appropriate design for the use cases you're
talking about.
Simon
--
Simon M. Brocklehurst, Ph.D.
Head of Bioinformatics & Advanced IS
Cambridge Antibody Technology
The Science Park, Melbourn, Cambridgeshire, UK
http://www.CambridgeAntibody.com/
mailto:simon.brocklehurst@CambridgeAntibody.com