“Once an object escapes, you have to assume that another class or thread may, maliciously or carelessly, misuse it. This is a compelling reason to use encapsulation: it makes it practical to analyze programs for correctness and harder to violate design constraints accidentally.”

Brian Goetz

Brian Goetz - “Once an object escapes, you have to...” 1

Similar quotes

“Immutable objects are simple. They can only be in one state, which is carefully controlled by the constructor. One of the most difficult elements of program design is reasoning about the possible states of complex objects. Reasoning about the state of immutable objects, on the other hand, is trivial. Immutable objects are also safer. Passing a mutable object to untrusted code, or otherwise publishing it where untrusted code could find it, is dangerous — the untrusted code might modify its state, or, worse, retain a reference to it and modify its state later from another thread. On the other hand, immutable objects cannot be subverted in this manner by malicious or buggy code, so they are safe to share and publish freely without the need to make defensive copies.”

Brian Goetz
Read more

“Men believe value is created by accomplishment, and they have objectives for the women in their lives. If awoman meets the objectives, he assumes she loves him. If she fails to meet the objectives, he will assume she does notlove him. The man assumes that if the woman loved him she would have tried harder and he always believes his objectives for her are reasonable.”

Scott Adams
Read more

“It is far easier to design a class to be thread-safe than to retrofit it for thread safety later.”

Brian Goetz
Read more

“From the perspective of a class C, an alien method is one whose behavior is not fully specified by C. This includes methods in other classes as well as overrideable methods (neither private nor final) in C itself. Passing an object to an alien method must also be considered publishing that object. Since you can’t know what code will actually be invoked, you don’t know that the alien method won’t publish the object or retain a reference to it that might later be used from another thread.”

Brian Goetz
Read more

“..Such practices and beliefs, which interfere with happiness, are neither inevitable nor necessary; they evolved by chance, as a result of random responses to accidental conditions. But once they become part of the norms and habits of a culture, people assume that this is how things must be; they come to believe they have no other options.”

Mihaly Csikszentmihalyi
Read more