Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Huge java class for android project, how to split it up?

In C++ I'm used to being able to split classes up into multiple files using the scope resolution operator (::), but in java it seems impossible to split a class between multiple files.

I've read that classes shouldn't be more than a few hundred lines, but that sounds like ideological nonsense from people who don't write significant applications.

I am writing an industrial Android application (not for consumers, for technicians using professional test and measurement equipment in conjunction with the app linked via bluetooth) and several of my android activities are more than 1000 lines long and I'm not even close to being finished. The primary activity is over 6000 lines long and I expect it to become much longer still... It's becoming very unwieldy and, like I said, in C++ I would just logically split the class among multiple source files, but I guess that's not an option here.

Is there any alternative that I am overlooking to reduce the length of my source files without actually cutting out code (which is not an option...)?

like image 493
CHollman82 Avatar asked Feb 22 '26 12:02

CHollman82


1 Answers

It's acceptable to have a class with more than a hundred lines (most of my classes I write are more than 100 lines long). The thing is, dealing with an Object Orientated language, one should categorize as much as possible, to make the code maintainable, intuitive and readable. Good luck with your app!

like image 146
Luke Taylor Avatar answered Feb 25 '26 02:02

Luke Taylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!