Ways to ensure unique instances of a class?+1 for Effective Java, I do have the book, sitting in my bag now actually :) However I was just curious as to other ways of achieving the uniqueness apart from the static factory/static method and the exception in the constructor. If there aren't any then I'll accept this.

Oct22

comment

Ways to ensure unique instances of a class?Sorry, massive facepalm, I don't actually need a NameFactory (or my equivalent) since there would one be one sub-class, the static method alone in Name would work fine. I was also just curious if there were other ways of ensuring uniqueness apart from the method(s) I mentioned. edit: Sorry hadn't seen your post!

Oct22

comment

Ways to ensure unique instances of a class?@RobertHarvey The actual class I'll be using it on is almost as simple as the Name class I use in the example, it just seems a waste to have a NameFactory and a Name class to get uniqueness for something so small, I was wondering if there was a more succinct way.

Ways to ensure unique instances of a class?@MarcB I'm aware of the singleton pattern but I thought that ensures only one instance of a class is possible? I want multiple instances, different values. Sorry if the question isn't making that clear. edit: Only saw first comment before posting.