Search Blog

Search duranek.blogspot.com

Wednesday, January 18, 2012

Immutable Class


immutable class:

1) class must be final
2) All methods must be final
3) All members must be private and final
4) There will be no setter methods
5) Constructor is public
6) If member variable is an Object, then getObject method must return 
a new Object with same values. Don't return the reference
7) If member variable is an Object then constructor must create new Object with
the values of the object.
8) If you want to change an amount in the class for example, you always create
new Object with new value.
9) Eger member variable larda List varsa, listi get yaparken,
Collections.unmodifiableList(mOBList);
yapacaksin. Listenin icindekiler de immutable olmak zorunda.

No comments: