Long .java files =\

Put your problem here if it does not fit any of the other categories.

Long .java files =\

Postby Skripi » Sun Jan 30, 2011 10:22 am

Hey guys!!

I'm currently a student at uni, and I've been taught that long class files are generally a coding smell. I'm currently writing an app with lots of dialogs on the one activity and a largish menu. It's all necesary to the class, but I'm getting a coding file of about 600+ lines of code. Is that normal for an android activity class?

It seems quite long to me, but I can't figure out a way to refactor the dialog boxes into another class or something.

Is there an easy way to just quickly throw some dialogs into a static class to manage code easily? or is just having a 600+ lines of code file fairly normal for an activity class?

Cheers,
Skripi
Skripi
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Jul 24, 2010 6:06 pm

Top

Re: Long .java files =\

Postby visivi » Wed Feb 02, 2011 5:30 pm

Meh, dialogs take a lot of space. I'm currently working on an Activity which has 1500+ lines.
While it is important not to stuff everything in a single class (OO-principle), sometimes it can get unmanagable if you create different classes for everything.
visivi
Developer
Developer
 
Posts: 29
Joined: Mon Nov 01, 2010 3:59 pm

Re: Long .java files =\

Postby jonbonazza » Thu Mar 10, 2011 2:48 am

The length of a java file does not necessarily mean anything. When it comes to coding practice, the things to keep in mind here are:
1) Every class (excluding inner classes) should have it's own file.

2) Every method should do one thing and do it well.

Java is strict about number 1 as it won't even let you add a public scope to a class unless it is in its own file.

What number 2 means is that you will likely have many function calls inside each function, and many private support functions should exist in each class. Due to this standard, it's actually safe to say that a properly designed class that does anything remotely complex should actually be relatively long.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 19 guests