什么是使用内部特性的好处? [英] What are the benefits of using properties internally?

查看:144
本文介绍了什么是使用内部特性的好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问来自会员上课的时候​​之外,但指的是类变量内部时,是它更好地满足其私有成员打电话,或者用自己的干将封装显然是有益的和必要的?如果您的getter直接返回变量,有任何性能差异

Encapsulation is obviously helpful and essential when accessing members from outside the class, but when referring to class variables internally, is it better to call their private members, or use their getters? If your getter simply returns the variable, is there any performance difference?

推荐答案

不应该有一个显著的性能差异,你坚持使用属性的原因是因为这是封装的整点。它使那些私有成员的所有访问一致性和控制。所以,如果你想改变属性的getter / setter你没有想到我需要在其他地方复制相同的功能,我决定直接访问私有成员?

There shouldn't be a significant performance difference, and the reason you stick to using the properties is because that's the whole point of encapsulation. It keeps all accesses of those private members consistent and controlled. So if you want to change the property getter/setter you don't have to think "do I need to duplicate the same functionality elsewhere in the places where I decided to access the private member directly?"

这篇关于什么是使用内部特性的好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆