• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Singleton Instance

Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm putting this question here since it's a case of implementation rather than theory.
In the Singleton Creation Pattern there only ever exists a single instance of the object. My problem is that I want to model application properties as a Singleton (eg MyProperties.getProperty(xxx)) but also be able to have multiple version of the Properties so that each can control a different area.
To paraphrase, I want a single instance of a properties wrapper, but also be able to extend it so that I can have Application properties, Email Properties, etc etc and have the ability for some of them to be updated dynamically if the source file changes and others not...
So, as I was writing this I think I might be able to achieve this using a Properties Factory that DOES have instances but returns an instance based on what was asked for. If anyone wants to help flesh this out a bit I'd appreciate it. (No, it isn't an assignment )
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's interesting to note that the Singleton Pattern, as expressd in "Design Patterns" actually allows for multiple instances. Limiting the instaces to just one, is actually just a special case of limiting the number of instances to any particular number.
In your case, though, I really think that a factory approach is a much better solution. If you really insist, you can make your factory a singleton, but I'd try really hard to make it a regular constructed object and either pass it around or place it in a session or some other semi-persistent repository. Ill-considered over-use of the Singleton pattern is one of the most common maintainability problems I see these days.
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic