"Classes should be immutable unless there's a very good reason to
make them mutable....If a class cannot be made immutable, limit its mutability as much as possible."
- Josh Bloch
I never thought of class immutability and its importance until I read Josh Bloch's statement quoted on a site about Java practices. There must be something about it that Bloch would quote such a tough statement. And it's true! A programmer must defend his class's instance variables from being changed from outside itself (except for instantiating the class, in which case you'll use a constructor or a static factory), unless there is a very good reason for it. Yeah, that is coolness to the uttermost level. Another point learned. :]
Continually learning,
Jep
make them mutable....If a class cannot be made immutable, limit its mutability as much as possible."
- Josh Bloch
I never thought of class immutability and its importance until I read Josh Bloch's statement quoted on a site about Java practices. There must be something about it that Bloch would quote such a tough statement. And it's true! A programmer must defend his class's instance variables from being changed from outside itself (except for instantiating the class, in which case you'll use a constructor or a static factory), unless there is a very good reason for it. Yeah, that is coolness to the uttermost level. Another point learned. :]
Continually learning,
Jep
No comments:
Post a Comment