Java - Confused by the one class per file rule

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-12-25T20:42:47Z Indexed on 2010/12/25 20:54 UTC
Read the original article Hit count: 178

Filed under:

The one class per file rule in Java has me a bit confused. I writing an Android app and trying to implement the accepted answer to this question:

Common class for AsyncTask in Android?

which calls for an interface definition which class A implements and class B accepts as an argument to its constructor.

So I need an A.java and a B.java, but where does the interface go? Does it need a separate java file itself? Do I have to define it inside both A and B? If not how to import it?

Also I will have about 10 different AsyncTask classes, but I don't want to bother creating a new file for each one. What would you recommend? Is there a way to put all 10 classes in one file? Or should I create a big if/then block inside the class and pass an argument telling it which of the 10 different tasks I want it to do?

© Stack Overflow or respective owner

Related posts about java