|
-
Aug 20th, 2006, 08:16 AM
#1
Thread Starter
PowerPoster
singlton and other design patterns
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!
-
Aug 20th, 2006, 11:23 AM
#2
Re: singlton and other design patterns
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
I don't live here any more.
-
Aug 20th, 2006, 11:56 AM
#3
Thread Starter
PowerPoster
Re: singlton and other design patterns
ok i see, so pretty much a static class?
-
Aug 20th, 2006, 12:27 PM
#4
Re: singlton and other design patterns
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.
I don't live here any more.
-
Aug 21st, 2006, 10:06 AM
#5
Re: singlton and other design patterns
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.
-
Aug 21st, 2006, 01:12 PM
#6
Re: singlton and other design patterns
Does Visitor even count as proper OOP? Hmm. *Regards it with suspicion*
I don't live here any more.
-
Aug 22nd, 2006, 05:00 AM
#7
Re: singlton and other design patterns
It's more OOPy than OOP can hoop to be.
-
Aug 22nd, 2006, 06:59 AM
#8
Re: singlton and other design patterns
But does it know where it's towel is?
I don't live here any more.
-
Aug 22nd, 2006, 07:25 AM
#9
Re: singlton and other design patterns
Don't Panic, "Visitor Classes" often mention that demarcation may or may not be the problem!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|