what is "singleton"? I probably do know but not sure what the term is. Can someone give me:
* an example
* a description
what about the other design patterns like ableton or something?
Thanks!
Printable View
what is "singleton"? I probably do know but not sure what the term is. Can someone give me:
* an example
* a description
what about the other design patterns like ableton or something?
Thanks!
A singleton class is a class that can only be instantiated one at a time. They are quite rare and have very specific use. There's really nothing very special about them, all you do is have a public static flag of some sort (depending on the program you are writing) and then either create the new instance of the class or just pass the already existing one to whoever needs it. This way you never end up with more than one object of this type. Usually non-serializable.
Design patterns are for students :D
ok i see, so pretty much a static class?
No. Static classes don't let you instantiate them at all.
You can't have 2 instances of a singleton class, but you can have 0 or 1 instances.
There's nothing to stop them having static methods and properties of course.
Let me put it another way...
You could have an array of MySingletonClass, but there's no point because you'd either end up with one singleton and a load of nulls, or a whole array full of references to the SAME singleton object.
There are lots of patterns. Off the bottom of my head,
Factory, Prototype, Singleton, Visitor (very interesting, do read on this one), Command and Iterator.
Does Visitor even count as proper OOP? Hmm. *Regards it with suspicion*
It's more OOPy than OOP can hoop to be.
But does it know where it's towel is?
Don't Panic, "Visitor Classes" often mention that demarcation may or may not be the problem!