• Post Reply Bookmark Topic Watch Topic
  • New Topic

to inner class or not to inner class  RSS feed

 
Marcus Kelvin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it appropriate to make a package access class used only by one other class a private inner class if it is otherwise unnecessary?
 
dennis deems
Ranch Hand
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's appropriate, especially if the potentially inner class exists solely to support the potentially enclosing class (like listeners, label providers, etc). On the other hand, if the enclosing class is already large, I might decide to leave things as they are. Large files are harder to work with.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis' answer is good. In general you'll want to keep the scope of classes, interfaces, variables, methods etc. as limited as possible. The more stuff you have in a certain scope, the more complicated your program becomes; the less stuff, the simpler. A good API doesn't leak information about implementation details to the outside.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!