I want to create an Entity Manager that realizes the Singleton pattern. The entities are Apartments.
The program adds properties to a list and they can be read out of the list.
Here is my implementation so far:
Estate Manager Class
Entity not found exception
My problem is that I dont exactly understand how Im supposed to integrate Singleton with the Entity Manager.
Any helpful pointer would be appreciated!
Dennis Von Valkenburgh wrote:I have now solved the Singleton part as follows:
OK, but I'm still not sure what this "entity manager" is (a) supposed to be, or (b) why you think that it needs to be a singleton.
And sorry, but I particularly dislike the use of the "initalize-on-demand-holder" idiom. It's simply "noise code" and, in your case, NOT needed.
That idiom is for use when creating the default instance is prohibitively (and I mean CPU seconds or minutes) expensive; not when you're simply calling
new EntityManager() (which does nothing).
For any other case (ie, 99.9999% of the time), just define an eagerly initialized private field.
This class would also appear to be mutable, which I also suggest is NOT a good idea.
Perhaps you could answer my two questions at the start, or (maybe even better) explain to us, in English, what you're trying to do.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here