The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 You Are What You Is: Defining Object Identity
Subject:  Re: If you run into this, your program is broken
Date:  2006-07-28 12:30:30
From:  breilly
Response to: If you run into this, your program is broken


Don't forget about this condition:

At that point your object has "settled" on its identity. Only after this point, it's ok to put this object into a hash structure.

This is difficult to enforce with the flag approach. The only alternative that I know of is to not allow the object to exist and not be in its settled state, which would mean getting it to a settled state by the time the constructor is finished.

Exception: if object construction happens entirely behind a factory or DAO. This can be difficult to accomplish. For example, what scope do you give the constructor so that the factory/DAO can access it but client code can't (including subclasses of the factory/DAO if not final). Then, you're left with the task of carefully reviewing the factory/DAO code to make sure it doesn't violate the rules. It certainly can be done, and I'm sure there are cases where it's necessary, but I would tend to avoid it if possible.


 Feed java.net RSS Feeds