JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Singleton Wrapper | Reply
Doesn't the singleton wrapper pattern seem to be useless? I mean, the singleton user can himself manage the reference, rather than using the wrapper.
Re: Singleton Wrapper (response to post by Samnel) | Reply
It's a convienence class for the user so he doesn't have to manage it himself and won't screw up that implementation (as an example - see how screwed up the implementation that was posted over at javalobby: http://www.javalobby.org/java/forums/t77060.html).

The point is that if the component has potential to be used in a singleton, providing a wrapper class provides a pretested convience implementation that they can use.
Re: Singleton Wrapper (response to post by Samnel) | Reply
A proper singleton implementation is far more complicated than many people think - there are quite a few ways to get it wrong. Therefore, implementing it once and then reusing is a great idea.
Re: Singleton Wrapper (response to post by Samnel) | Reply
Thanks .The explanation seems good enough for singleton pattern to implement.
Re: Singleton Wrapper (response to post by Samnel) | Reply
We must never forget the "Double Checked Locking" mechanism as well :)
Re: Singleton Wrapper (response to post by kamals1986) | Reply
do you think we need double checked locking always??
what will be the problem if classes has early loaded instance and then using singleton is there any problem??
Re: Singleton Wrapper (response to post by Samnel) | Reply
The implementation of basic singleton design pattern is very simple as it involves only one class which is responsible for creating an static member of itself and the returning the reference to the static member but there are multiple loop holes like race conditions between two thread.. which needs to be handled carefully using synchronized block. As suggested above it is better to create a design pattern utility library which handle all edge cases and then use it in multiple places instead of re writing same program multiple times .
RSS