Results 1 to 9 of 9

Thread: singlton and other design patterns

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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!

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: singlton and other design patterns

    ok i see, so pretty much a static class?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: singlton and other design patterns

    It's more OOPy than OOP can hoop to be.

  8. #8
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: singlton and other design patterns

    But does it know where it's towel is?
    I don't live here any more.

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width