是具有大量的getter和放大器;塞特斯一个好主意? [英] Is having a lot of getters & setters a good idea?
问题描述
在编写您打算开源应用程序(在Java),是一般一个好主意,有很多的getter和放大器; setter和make变量私有?更具体地讲,如果要成为一个 Android应用程序后,会回答上面的问题仍持有?
When writing an application(in java) that you intend to open source, is it generally a good idea to have a lot of getters & setters and make variables private? More specifically, if that were to be an android application, would the answer to the question above still hold?
编辑:如果你们能够给我一个具体原因,为什么它的更好,这将是真棒。
If you guys could give me a concrete reason as to why its better, that would be awesome.
推荐答案
如果你正在讨论的getter和放大器;结果 - :在机器人,检查哪些Android文档告诉setter方法
<一href=\"http://developer.android.com/guide/practices/design/performance.html#internal_get_set\">Avoid内部getter / setter方法 结果
在Android上,这是一个坏主意。虚拟方法调用是昂贵,远远超过了实例字段查找。这是合理的,遵循共同的面向对象编程实践和在公共接口getter和setter,但是在类中,你应该总是直接访问域。
If you are discussing getters & setters in ANDROID, check what android documentation tell:-
Avoid Internal Getters/Setters
On Android, this is a bad idea. Virtual method calls are expensive, much more so than instance field lookups. It's reasonable to follow common object-oriented programming practices and have getters and setters in the public interface, but within a class you should always access fields directly.
这篇关于是具有大量的getter和放大器;塞特斯一个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!