班级何时应该使用自己的getter/setters而不是直接访问成员? [英] When should a class use its own getters/setters vs accessing the members directly?
本文介绍了班级何时应该使用自己的getter/setters而不是直接访问成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Eclipse中生成setter和getter时,选项之一是在类中使用getter和setter,而不是直接访问类成员.这种级别的内部封装是有用的还是采取一个好主意太远了?
When generating setters and getters in Eclipse one of the options is to use the getters and setters within the class rather than accessing the class members directly. Is this level of class internal encapsulation useful or is it taking a good idea one step too far?
查看全文