File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes A new file 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 "A new file or not" Watch "A new file or not" New topic
Author

A new file or not

Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

Hi Yall,
I have a question about the style of programming.

If I have to create a small class/interface, will it be a good idea to create a new file or just write it along the file which will use it. I always thought it will be best to always separate classes and interface in each java file.

I am interested in others opinion or experience.

Holler,
Garry


star chaser..
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1614
    
  10

When you say interface... you don't mean a real interface (as in something a class implements), right?

You mean like a user interface?

I like this format myself

Main method starts the user interface:



and then create a HAS a relationship so the UI can interact with the algorithms you need.

Dunno if it's "javaranch correct" but it's what I've done and it seems pretty clean.


When you do things right, people won't be sure you've done anything at all.
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

Here is what I mean....



My question is....
Is it in good practice to separate the OtherClass and ClassName in two files or one file?
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1614
    
  10

You can do either, but I make 2 separate files incase something else ever implements the same thing.

Again.... not sure of the JR right way.....
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
I think it's usually best to maintain 2 files unless one is an inner class.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
jQuery in Action, 2nd edition
 
subject: A new file or not
 
Similar Threads
Translation problems
URLyBird: reading database-file
Interface inside the class
How to rename a file in JAVA ?
a question about interface