With their 4.0 release, they’re introducing a new Property class that helps you generically set or get internal values for an object. Described here (scrolling down a bit): http://developer.android.com/sdk/android-4.0.html#api and Defined here: http://developer.android.com/reference/android/util/Property.html
At the same time, they say to avoid internal getters/setters. http://developer.android.com/guide/practices/design/performance.html#internal_get_set
Am I missing something as to how the Property class doesn’t violate this rule? I understand it’s benefit in coding, but not in performance.
Thoughts?
It “violates” the rule. The rule, however, is not universal, as the document you cite goes to great pains to try to explain at the outset. That document outlines “micro-optimizations”. These, as the document states, “will almost never make or break your software”. Rather, they are things that you may wish to optimize in particular places that need it.
You do not need to avoid internal getters and setters unless they are causing specific performance problems. You can usually determine this by using Traceview and seeing lots of time spent in the getters and setters.
So, for example, in a tight loop over a large data set, trying to avoid getters and setters is probably worthwhile. Outside of scenarios like that, using getters and setters is unlikely to cause any material pain to you or the user. Again, let tools like Traceview be your guide.
Now, curiously enough, some of the intended uses of
Property(e.g.,ObjectAnimator) might seem to require more micro-optimization than your average hunk of code. I guess you will simply need to see whether the animation runs as smoothly as you want. I haven’t yet usedObjectAnimatordirectly, let alone with ICS’sProperty, so I can only hope that this all works well.