• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single instance of application

 
Sam Stackly
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I want to let user have one instance (and only one) insatnce of application running (is that singleton?), but it seems I have problem with that, here is my code

is this the right way?
Thanks in advance,
Sam
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,
Yeah that's a Singleton alright. But the question is why do you need it? Before you use a Singleton anywhere in this assignment, you should do a search on the subject and read the posts by Peter den Haan.
Here is one of many (e pluribus unum?) by Peter regarding the use of the Singleton Pattern:

I've got nothing to add to Thomas' words. It's been said numerous times that Singleton is one of the most abused design patterns around, and I tend to agree.
Use the Singleton pattern only when there is a fundamental, inherent reason why you cannot have more than one instance of a given class. The fact that you do not need or want more than one copy in a specific application is not good enough. What is true today will likely change tomorrow.

So consider closely the advice of an expert, before proceeding with this.
Hope this helps,
Michael Morris
 
Sam Stackly
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
I was thinking about server(application) GUI I have, It doesn't make sense to have two or more instance of it, is that right?
Regards,
Sam
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,

... It doesn't make sense to have two or more instance of it, is that right?

That's right for today, but what about next year?
As Peter indicates "The fact that you do not need or want more than one copy in a specific application is not good enough. What is true today will likely change tomorrow."
So once again, I admonish you to consider the use of the Singleton pattern here and to only use it if you feel that you have reasons other than the fact that you only want one copy here.
Hope this helps,
Michael Morris
 
Sam Stackly
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You make me to really think about this,
:roll:
Thanks again
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic