in reply to Re^3: Your favorite objects NOT of the hashref phylum
in thread Your favorite objects NOT of the hashref phylum
The singleton pattern is often used in that way by those who have not been taught better (or who are simply lacking in mental horsepower).
Singleton objects (or similar) can be useful however. Because they hide the fact that there is only one, it can be changed later to have more than one. Say for example your program logs to a logfile, so you use a singleton object factory to return a thin class with a file handle and a print_to_log method. Later you want to use a different logfile depending on the name of the method (or whatever) - the object factory can be changed to return you a different logger object based on your criteria. You're still caching file handles, just a number of them instead of only one. If you used a global variable you would have to change every point where you print to that filehandle to achieve the same effect.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fun with Farcical Factories (Was: Re^4: Your favorite objects NOT of the hashref phylum)
by BrowserUk (Patriarch) on Mar 28, 2006 at 14:37 UTC | |
by aufflick (Deacon) on Mar 30, 2006 at 12:15 UTC |