Object-Oriented Programming – Benefits for Android Development

androidobject-orientedperformanceprogramming practices

My development on Android is based on scientific programs and while I'm building these most of the code is in one or two long classes. When I come to deploy these programs I try to decouple everything and use classes and objects like I would on a Java desktop application.

However reading guide Designing for Performance | Android Developers about Internal Getters/Setters it seems OO is not a good approach.

My question is what is best approach when designed Android applications, should I still use lots of classes with getters/setters and lots of object passing around. This seems counter intuitive thinking about the architecture of Android, but it also does not seem right to have lots of code in long classes.

I have looked at source codes from other projects and these seem to follow the OO approach.

My applications involve heavy image processing and time and performance is important.

I am more of a science researcher than a programmer so thanks in advance for any help.

Best Answer

Write dumb code

"Often, the way to write fast code in Java applications is to write dumb code -- code that is straightforward, clean, and follows the most obvious object-oriented principles." -- Brian Goetz

Don't get me wrong - there is a chance that particular object design may have substantial performance impact in some particular case on specific execution path in some application on some device - why not, everything is possible given the variety of Android devices. Know what? there is even a chance of it having an opposite impact on some other device, why not.

If (if) that happens, if (if) you'll somehow get a clear, solid, tested and proven justification of specific performance impact - then (then), go ahead, implement whatever tricks necessary to reach required performance, no matter how perverse they may be (BTDTGTTS). Until then, though, drop any baseless assumptions that just may come to your mind.

Until then... Just. Drop. It.

Developers love to optimize code and with good reason. It is so satisfying and fun. But knowing when to optimize is far more important. Unfortunately, developers generally have horrible intuition about where the performance problems in an application will actually be... Most performance tuning reminds me of the old joke about the guy who's looking for his keys in the kitchen even though he lost them in the street, because the light's better in the kitchen... (Brian Goetz)

Related Topic