• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Singleton pattern

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my situation
each user of our application will have a set of credentials(username/password) saved in our database to login to a partner application appB.
the credentials can be added for the first time user tries to login to the appB. thereafter user can update the credentials.
i am planning to make the credential class singleton since i need only one instance per user.
is the singleton pattern creates one instance for all users or one instance of credential per user?? please suggest
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is the singleton pattern creates one instance for all users or one instance of credential per user?? please suggest



Does the Singleton pattern create one instance for all users or one instance per user?

The purpose of this pattern is to limit the number of instances of a class. A single instance is typically what is implemented. However, the design pattern can be used to limit the number of instances to three or four as well.

i am planning to make the credential class singleton since i need only one instance per user.



This is not a correct way to implement the Singleton design pattern. The purpose of the pattern is to limit the number of instances in an application, not per user. If you implement the credential class as a Singleton, each user will get the same credential as there will only be one instance.

Forget about the Singleton design pattern. It comes from non object-oriented roots and is typically a flaw whenever it is used, in my opinion.
[ September 02, 2008: Message edited by: James Clark ]
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Credential class itself cannot be Singelton since what it represents is the user's credentials which varies on a per-user basis. The Authenticator class which authenticates credentials can be Singleton, perhaps it can accept a username and password and return a Credential class instance when it passes authentication.
 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic