Standing on the shoulders (well, maybe feet) of giants
[ start | index | login or register ]
start > comment-Value Object Sample Code v2-2

comment-Value Object Sample Code v2-2 commented Value Object Sample Code v2

Created by matthies. Last edited by matthies, one year and 151 days ago. Viewed 263 times. #2
[diff] [history] [edit] [rdf]
labels
attachments
"There can never be two Currency instances that both represent the US$."

It should be noted that serialization/deserialization can create duplicate Currency instances representing the same currency, unless the class implements an appropriate writeReplace() method (returning an object implementing an appropriate readResolve()).

In general, great care has to be taken to make this "only one instance" work. Unless there's a very good reason to have this guarantee, it's usually simpler and more robust to just allow for multiple instances.

The sample code provided here is dangerous in that people are likely copy it without understanding these issues in detail and not fill out the blanks correctly.

2 comments (by Dirk Riehle, matthies) | post comment
Copyright (©) 2006 by Dirk Riehle or the respective authors. All rights reserved.