我推薦這本書:由安卓遊戲開發者Mario Zechner和Robert Green開發的Android 4遊戲開發。OOP設計vs智能手機的性能
192頁的書中指出:
Method calls have a larger associated cost in Dalvik than in other VMs. Use static methods if you can, as those perform best. Static methods are generally regarded as evil, much like static variables, as they promote bad design, so try to keep your design as clean as possible. Perhaps you should avoid getters and setters as well. Direct field access is about three times faster than method invocations without the JIT, and about seven times faster with the JIT. Nevertheless, think of your design before removing all your getters and setters.
現在,這是否有時下巨大的影響?性能和設計之間最好的是什麼?因爲如果我要擁有靜態變量和方法,它會在應用程序終止之前存在於RAM中,如果我的應用程序太大而且android 2.3將成爲市場的一部分,那將會很糟糕。
爲了優化性能,有很多事情違背了良好的面向對象操作規範,但是我個人只會將它們作爲最後的手段。在達到這個階段之前,還有很多其他的東西可以優化。如果你必須這樣做,這是一個問題,你想交換代碼質量來提高性能。 – hidro
吸氣劑和吸附劑也因某些方面受到批評。你可以用'final'字段替換它們,也可以用於O/R映射。其餘部分:最後優化1%,確實很慢。 –