Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Objects

Generally, the internal state of an object will be hidden from the outside world, and any access to that state, or changes to it, will be done by that object's publicly visible methods, including the trivial stuff. Because the trivial stuff grows into non-trivial stuff, and before you know it, the whole world knows that your Person object stores its phone number as an Int instead of a String and is accessing it directly, making reversing that questionable decision very messy. Better to have a phoneNumberAsInt() method for any object that needs, well, the phone number as an Int.