"No practical value"!? The value of a singleton is in where it's used. In this case, it may seem like less value, but if you wanted to switch from a singleton to a pool structure, the code change is nil.

Take for instance an object that used semaphores and locking to prevent multiple people exuting at once. For instance, a banks total available funds, not per account basis. One person would want to withdraw $50, but you don't want to create race conditions.

If taking out money starts to create contention, you can create pools of bank totals so that multiple people can withdraw and deposit at the same time without race conditions, and less contention. If $5 million were broken out into pools of $1 million, 5 people could withdraw and deposit at the same time w/o creating a race condition provided each person got a different object, one for each of the million. As pooled items aren't needed, they can be put away and dealocated.

Where does this all lead up to? If you use the singleton pattern, everyone would use the single, lockable object. If locking becomes a problem, then you can change the code in whatever creates your singleton instances to create a limit of 5 pooled objects. If all 5 are in use, you have to wait. if 4 are in use, you get a new one. Basically, a pool, as you and I know of. Using the pattern will result in less code change. If you use a global, you can't accomplish this. If you are using a singleton, it's a lot easier. In some OO languages, this is very easy to implement. In others, it takes foot work. But by far, it is not useless.

----
Give me strength for today.. I will not talk it away..
Just for a moment.. It will burn through the clouds.. and shine down on me.


In reply to Re^2: Log::Log4perl and singleton design issue by exussum0
in thread Log::Log4perl and singleton design issue by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.