▼
Immutable
- We cannot change the value of an object once it is created.
- Declare a class as final so that it cannot be extended.
- All class members should be private. So that direct access can be avoided.
- And class members are initialised only once using constructor.
- All the members of the collections framework are Returned with a deep copy.
- There should not be any setter methods, Which is generally used to change the value.
- Just getter methods And returns, copy of the member variable.
- Example string, Wrapper classes etc.
- Example
No comments:
Post a Comment