Effective Java : Making a class as private nested class (Item 22)
This question already has an answer here:
When I read that book, I took that paragraph this way:
If a class is used by another class and there is no other way it would be used by some other class by any means, move it to the class that uses it as an inner class. This usage renders the inner class as a "private" feature of encapsulating class. Therefore, in order to keep things tidy, somewhat similar to encapsulation, the writer advised to make the move.
From that point of view, it made sense to me.
In short, encapsulate where ever it makes sense but don't force it if it does not.
链接地址: http://www.djcxy.com/p/92026.html