Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where can use single object

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know the sigleton design patter but i dont know where should i use it.
what are the applications of singleton design pattern?
as ia m developing online examination using jsp, servlets can i use this singleton deg pattern in my application???


 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally I'm trying to avoid using singletons in building applications. Unfortunately it isn't always easy, for example configuration is something required for most of applications and fits in singleton pattern perfectly.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Singleton is most useful when you need to control access to a particular resource. For example, in my test engine one class controls all loading of XML test script documents and tracks the usage of these DOMs. Obviously, having more than one instance of this class would be a big waste of memory and make debugging harder. Therefore the constructor is private and a static "factory" method handles initial creation of the single instance.
Bill
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanx but can i sue this concept for user login
so that the only one user can login with his PIN and no other can login by using the same PIN?
can i do this ?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by saikrishna cinux:
ok thanx but can i sue this concept for user login
so that the only one user can login with his PIN and no other can login by using the same PIN?
can i do this ?


No. Singletone is not for that purpose.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chetan is correct.

You might have a UserManager class using the Singleton pattern since you only need one UserManager for the entire application. UserManager could track all logins and be able to tell if a particular PIN was in use.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic