4. Object Structures, Aliasing, and Encapsulation
4. Object Structures, Aliasing, and Encapsulation
4. Object Structures, Aliasing, and Encapsulation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Explanation:(Immutability)We assume that equality for the primitive typesis defined by „==“ <strong>and</strong> for reference types bysome reasonably defined method equals.An object X is called (observationally) immutableif after termination of its constructor callany two invocationsX.m(p1,...,pn) <strong>and</strong> X.m(q1,...,qn)with pi equals qi (1≤ i ≤ n) either- yield equal results or- throw equal exceptions or- both do not terminate.A class C is called immutable if all instances of Cin any program execution are immutable.Remark:• Immutability is usually defined by prohibitingstate changes <strong>and</strong> dependency of „external“ state.• About 660 concrete classes in Java‘s st<strong>and</strong>ardlibrary are immutable (about 20%)13.05.13© A. Poetzsch-Heffter, TU Kaiserslautern12