Timeline for What other patterns can I use for this singleton?
Current License: CC BY-SA 3.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 22, 2012 at 17:55 | vote | accept | ssube | ||
| Aug 22, 2012 at 15:03 | vote | accept | ssube | ||
| Aug 22, 2012 at 15:24 | |||||
| Feb 16, 2012 at 23:10 | comment | added | ssube | @jhocking Singletons aren't innately bad, there is a very valid use case for the pattern, and the Server is it: all the state it governs is process-specific but must be accessible anywhere within the process and there must never be more than one instance. Making it anything else complicates a lot of things. The "start point" is the creation of a core. | |
| Feb 16, 2012 at 22:07 | comment | added | jhocking | @peachykeen For the end user that results in the same behavior, but for the developers that has the advantage of not using singletons. Because you asked this question I assumed you already knew that singletons are kind of bad news, but if you need that explained then that is a whole other conversation. And by "a fifth Main object" I didn't mean another singleton, I'm talking about whatever is the start point for your program's execution. | |
| Feb 16, 2012 at 21:45 | answer | added | Dipan Mehta | timeline score: 3 | |
| Feb 16, 2012 at 21:31 | comment | added | Ray Saltrelli | It sounds like the biggest problem might be that the config file of the first Core created determines everything. You might need multiple configuration files, one for global configuration and one for core specific configuration. This way the Server has what it needs with out relying on any Cores and the Cores can still enrich the Server's configuration as they're loaded since the Server is a singleton. | |
| Feb 16, 2012 at 21:25 | comment | added | ssube | @RaySaltrelli Where do the Server Logger and Parser get their information? Cores will need to share variables with the Server's Parser, a path from the configuration file, for example (with some good reasoning, that could probably be removed). I certainly don't want to log to multiple places, that would make a bug-reporting nightmare. | |
| Feb 16, 2012 at 21:14 | comment | added | Ray Saltrelli | So if the Logger and Parser are not singletons and the Server and Cores each have their own instances with different configurations, what problems does that introduce? | |
| Feb 16, 2012 at 21:11 | comment | added | ssube | @RaySaltrelli That's a possible solution. At the moment, only the first configuration is used; for example the Core does if (!Logger.IsOpen) Logger.Open() and so on. While the Parser and Logger as singletons is useful for a variety of reasons, it restricts them to single configurations, which is the problem that caused me to reevaluate using singletons. | |
| Feb 16, 2012 at 20:50 | comment | added | Ray Saltrelli | OK, so let me try again :-) The Server is a singleton. You instantiate a number of Core objects and each Core object loads a different config file. The Server and Cores all share the same Logger and Parse which are also singletons. You want the Server to use the Logger and Parser with a certain default configuration and you want each Core to add additional configuration to the existing Logger and Parser from its config file when it is created. Am I getting warmer? | |
| Feb 16, 2012 at 20:37 | comment | added | ssube | @jhocking Why? What benefit does that provide over the current model? Having a singleton that creates, holds and passes instances vs having each object be a singleton gives the same end behavior. | |
| Feb 16, 2012 at 20:36 | comment | added | ssube | @RaySaltrelli That one of the problems in one of my ideas, not the current state of affairs. At the moment, the Logger and Parser are also singletons, with some finalization done when a Core is created (adding of variables and such). If the Server was to get its own instances, then the data source would become an issue. | |
| Feb 16, 2012 at 20:34 | comment | added | Ray Saltrelli | Let me just restate your problem to make sure I understand it correctly. Your Server object is a singleton. You instantiate a number of Core objects and each Core object loads a different config file. Each Core has a Logger and Parse and the Server also has a Logger and Parser. The Core's config file has data needed by the Core's Logger and Parser. Correct so far? If so, where does the config data for the Server's Logger and Parser come from? | |
| Feb 16, 2012 at 19:57 | comment | added | jhocking | Can you have a fifth Main object that instantiates Core, Server, Logger, and Parser? Then you can have it instantiate a Logger and Parser first, and then pass those objects as parameters to the constructors for Core and Server. | |
| Feb 16, 2012 at 19:04 | history | asked | ssube | CC BY-SA 3.0 |