0

Let's imagine an OOP framework. There are classes according to database model. And there are some generic classes, which cannot be linked to model - totally written by me, they are doing some calculations, etc. They can't even be static classes - there must be one instance, in some cases (so not everytime). And I don't want to create them everytime I plan to use. This is when I need to think of singleton - create that object when it's touched, and only once. But they say singleton is not good. Factory?

John Smith
  • 6,129
  • 12
  • 68
  • 123
  • If you are in charge of all the code you can simply create one instance of the class and pass it around. No need for a singleton or a factory. – Bart Nov 10 '13 at 12:40
  • 1
    alternatives to singletons: http://stackoverflow.com/questions/1300655/whats-alternative-to-singleton – bitWorking Nov 10 '13 at 12:46

1 Answers1

1

Disclaimer: I know nothing about singleton classes, first time i hear of them and i just read their description on StackOverflow.

You have autoloading available, why not using it?
I believe this is the right solution. It won't mess your current code and it's an easy solutions (easy is always good). What i'd do is to create an additional folder (or use an existing lib folder if the framework provides it) and set autoloading on it, then just work with classes - static and not -.

Hope it helps!

jnardiello
  • 699
  • 8
  • 15