in reply to Re: Log::Log4perl and singleton design issue
in thread Log::Log4perl and singleton design issue
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Log::Log4perl and singleton design issue
by BrowserUk (Patriarch) on Dec 19, 2004 at 20:02 UTC | |
by exussum0 (Vicar) on Dec 19, 2004 at 20:04 UTC | |
by BrowserUk (Patriarch) on Dec 19, 2004 at 21:13 UTC | |
by brian_d_foy (Abbot) on Dec 20, 2004 at 11:20 UTC | |
by exussum0 (Vicar) on Dec 19, 2004 at 22:08 UTC | |
by sauoq (Abbot) on Dec 19, 2004 at 23:14 UTC | |
|