The moose likes Cattle Drive and the fly likes Inner class or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Inner class or not" Watch "Inner class or not" New topic

Inner class or not

Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

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?

star chaser..
paul wheaton

Joined: Dec 14, 1998
Posts: 20973

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.


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.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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.
I agree. Here's the link:
subject: Inner class or not
It's not a secret anymore!