• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class or not

 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When coding, how do people make a decision on making a new file, placing classes on one file, or making it a private static attribute of a class.

To be specific, I am working on SortNames class and I created a class that implements a generic. I thought this class is small enough not create a new file, and others classes might use this capability so I decided to make the class within a file. How do others make their decision?
 
paul wheaton
Trailboss
Pie
Posts: 21683
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you start to speculate about how you might use something in the future, you have just touched a tar baby that you could become entangled in for all time.

Focus.

Do the bare minimum to meet the needs of the assignment.

80% of all developers fall into the "what if" trap. I want you guys to stay the hell out of it.

 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make the source of a class easy to find, give it a seperate file.

To make it hard to use, put it inside another class.

If I want to show a small, working example of something in a forum, to ask or answer a question, I try to put it into a single file, so it's easy to copy that whole bunch of stuff, put it into a file, compile and see for your own what it does / an error.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic