[Biojava-l] Private vs Protected

Matthew Pocock matthew_pocock@yahoo.co.uk
Fri, 03 May 2002 11:46:46 +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
> 
> 
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l@biojava.org
> http://biojava.org/mailman/listinfo/biojava-l
> 

Hi David,

I'm probably among the worst offenders in this. I tend to make 
everything private if possible and all fields final if possible. I feel 
that it lets the compiler trap many things for you, and prevents 
sub-classes violating contracts that thier pairents assume (java doesn't 
have full pre-/post- conditions - design by contract is great). Of 
course, if we didn't propperly consider how the class or interface may 
be implemented differently and didn't provide APIs to allow developers 
to extend these, then we need to look at these cases again. Could you 
give us a quick rundown of where you have been hampered by 
private/protected members?

Thanks,

Matthew