擅长:python、mysql、java
<p>OOP中的getter/setter主要是维护<a href="http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)" rel="nofollow noreferrer">encapsulation concept</a>,并对对象的内部变量进行访问控制、输入验证、触发等操作,这是OOP设计中的一个概念,适用于所有编程语言。你知道吗</p>
<p>你可以用任何编程语言定义公共成员变量,但是一个好的OOP设计不应该对外公开任何内部实现细节,一个类应该只公开所需的内容,并且应该严格控制对它的访问并验证输入。你知道吗</p>
<p>有关更多信息,请查看<a href="https://softwareengineering.stackexchange.com/questions/176876/why-shouldnt-i-be-using-public-variables-in-my-java-class">this Programmers Stack Exchange question</a>,这里的信息通常适用于OOP。你知道吗</p>