5 ms·
I especially agree with "This means that objects can only communicate by calling methods". I think we can add another thing - the object can also expose readonl
by edwinyzh 8y ago
I especially agree with "This means that objects can only communicate by calling methods".
I think we can add another thing - the object can also expose readonly properties, which allows external modules easy accessing the object's state but cannot change it.
- jakobegger 8y agoRead-only properties would be implemented as methods that return the value of an internal variable. There should be no way to directly access the internal state of an object, even if it is read-only -- because that would prevent you from changing internal details (eg. do you store the property in a float or a double?), breaking the "encapsulation".
- edwinyzh 8y agoSure, if not implemented as methods that return the value of an internal variable, how can one achieve the "readonly" goal?