I wrote a standalone singleton class (scaffold) tonight that serves as a facade to a few other classes, including a template class and a view class. Templates and views are both named and instances of each are stored in the scaffold object. Templates can contain views and views can contain other views. A template and it's contained views is rendered when:
scaffold->render('template_name')
Making scaffold a Singleton seemed like a good idea because:
- I want to control when and how the object is constructed
- I only want one instance (the gui will only be rendered once, regardless of the template which is rendered)
- All state can easily be released from the scaffold class (if, for testing reasons or whatever, I wanted to)
Does this seem like an acceptable use case? If not, what specific design considerations am I overlooking?
No religious wars, please. I didn't include the language because I'm hoping for a language agnostic consideration, but I will say:
- Scripting language
- Single threaded
scaffold
have? This sounds more like a case for a static method than for a singleton. – Carson63000 Aug 1 '12 at 11:03