After 1000s of private
s in private
it occurred to me that it may not be needed
public class Outer {
private static class Inner { /
The answer depends on how you currently use inner classes.
My philosophy for inner classes is to reduce the burden of refactoring. I maintain encapsulation of inner classes: private
methods and fields of the inner class are not accessed from the outer class even though they can be. The point of inner classes, then, is to reduce its scope to only the containing class. That way, if later an inner class can be reused elsewhere, it requires almost no work (and a trivial amount of work for non-static
inner classes) to move it into its own file.
Whether or not the above is your style will affect the following reasons for dropping or keeping the private
around methods/fields.
The reasons for dropping private
are:
The reasons against dropping private
are:
private
serves as documentation: the outer class shouldn't use these methodsprivate
is kept, it makes it much easier to promote an inner class to its own fileprivate
is dropped, there are two styles for public
inner classes and private
inner classes: more for the programmer to think aboutprivate
is dropped and the inner class was made public
, suddenly everyone who has access to the outer file has access to the inner class's private dataGiven the above style, I think the case against dropping is stronger.