Android, object-oriented programming and design for productivity

I am a complete noob for android, but I have been programming C # for a long time. I am writing an Android application and got to the point where the C # programmer in me wants to start creating a loosely coupled design and moving the code to different layers using interfaces, etc.

But then I come across Development Recommendations that tell me to avoid creating an object , and then he also says to optimize in court .

I only build on good design and then deal with performance issues when they appear?

The last thing I want to do is do the job of creating the application and do it poorly. Can someone point me to some sample applications that are well designed and have good performance, or just give some recommendations?

thanks

+4
source share
3 answers

I found AndEngine to be reasonably thought out, and it should be related to performance, as it is a game development library - so that you can pull out a copy of it and read the source.

In Design for Performance, I would like to point out this statement:

Please note that although this document primarily covers micro-optimizations, they will almost never make or break your software. Choosing the right algorithms and data structure should always be your priority , but outside the scope of this document.

An example of this is the creation of a particle system. A good way to model is to have a ParticleSystem object that contains a collection of Particle objects ... perhaps these Particles implement the Particle interface ... this is not the place to avoid creating the object. However, for performance reasons, you will want to optimize ParticleSystem to reuse Particle objects, and not to create them from scratch every time you create one of them.

Personally, I do not think that performance is a very limiting factor, but I believe that it will really depend on which application you create.

My opinion is to first create a suitable design, test performance and optimize from there.

+5
source

Pay attention to a quote from Donald Knuth, which appears in the same article:

"We must forget about small efficiencies, say, about 97% of the time: premature optimization is the root of all evil. The root of all evil."

Then, if you are dealing with the other 3%, you will see ...

+2
source

As a rule, the point is to keep the data structure as simple and normal as possible. How to not just throw hash tables of structure data just because it is easy to capture. Know how to do profiling ( here is my method ), and if you have a real performance problem, fix it. Otherwise, the simpler the better, even if it means simple arrays, lists, and O (N) loops.

The reason for maintaining a normal data structure is that if it is not, then it may have inconsistent states, and you will have a strong temptation to write a notification style code to try to keep it consistent. These can be real productivity killers. If you do, profiling will tell you what is happening. If you should have redundant data, I believe that it is better to be able to tolerate the temporary inconsistency that you periodically repair by transmitting data. This is better than trying to intensively ensure consistent notifications.

Another problem with an abnormal data structure is that it can have a lot of creation and destruction of objects. It can also be a real productivity killer, although you can improve it using the pool method.

+1
source

All Articles