in reply to Re^4: Log::Log4perl and singleton design issue
in thread Log::Log4perl and singleton design issue

... so you can create two, one or three on a whim. The singleton pattern allows control over that.

1, 2 or 3 instances of a singleton ... m'kay :)


Examine what is said, not who speaks.        The end of an era!
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
"Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo         "Efficiency is intelligent laziness." -David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^6: Log::Log4perl and singleton design issue
by brian_d_foy (Abbot) on Dec 20, 2004 at 11:20 UTC

    You don't create multiple instances, jsut multiple references. Each part of the program that needs a reference gets its own, so it doesn't have to rely on some other distant part of the program.

    For instance, Apache::DBI does this sort of thing so different things happening in mod_perl can share a database connection, even though they might be different applications.

    --
    brian d foy <bdfoy@cpan.org>
Re^6: Log::Log4perl and singleton design issue
by exussum0 (Vicar) on Dec 19, 2004 at 22:08 UTC
    The point is not to hardcode something somewhere. If you wish to use globals, go right ahead. I'm not trying to stop you. Just like you use enapsulation in OO for setters and getters for the flexibility of doing things during sets or gets, it's the same for singletons. It allows you to break the mold. Saying singleton's are useless is like saying sed is useless. If it were useless, people wouldn't use it.

    ----
    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.

      If it were useless, people wouldn't use it.

      Can you make the same argument about neckties?

      Neckties are useless, but some people think wearing them makes them more professional.

      -sauoq
      "My two cents aren't worth a dime.";
      

        Depends. Is it a columbian necktie?

        Makeshifts last the longest.

        but some people think wearing them makes them more professional.
        and therefore they're not useless.
        
        The traditional necktie, can be used as a tourniquet. Other than taht, they are merely a traditional fashion statement. Two times the usefulness. As Emerald would say, "Bam!"

        ----
        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.