"I'm not back." - Bill Harding, Twister
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Michael Morris:
Not quite Greg. You should also decide whether the class will be strongly immutable by declaring the class final, or weakly immutable by declaring the methods final. Also, you must protect all state which involves an object reference by making a deep copy of the referred object and returning the copy in a getter for that state.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Michael Morris:
Now, because of polymorphism, any context expecting an Integer will accept my MutableInteger, so I have in effect thwarted the efforts of the original class designer to provide an object whose value can't change.
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
"I'm not back." - Bill Harding, Twister
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Michael Morris:
I think that if you have a strongly immutable class you should have only private constructors and use static factory methods to get instances.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Don't MAKE me come back there with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|