Here are my points:
There is a difference between having only one instance of the object in the entire application vs. an object becoming singleton so that any one calling
new()will magically findtheInstance.In your case, there is no benefit of having server being singleton because no one is creating server other than
main(). It's just plain simple to have it as ordinary object. Even if it is singleton, it will be called only once!Parsershould never be singleton either for a different reason here. If i understood correctly,parser's only role is whencoreis launched; Ideally it should followuse-and-throwoatternpattern rather thansingletonEven
parsercontinues to serve some specific queries till corecorewants it, by designparsershould be one instance percorebecause same instance ofparsershould never share information about various differentcores. It makesparserdedicated per corecore.Most people design
loggeras a singleton. It is not really much big deal, however, if you are a multi-threaded system a singleton loggerloggeris a big villienvillain. First off, every singleton needs to be threadsafe. Suppose even if you make it thread safe, every time athread xcalls logger it is busy doingprintfforthread yso as a resultthread xwaits where aswhereas ideally you should be worrying about getting the maximum out of your quad-Core system and serve as many requestrequests as possible.Ideally the only genuine case where
loggershould be centralized or singleton is where the exact order of events must be registered one-by-one. For most purposes, different files and messages with itstheir own time stampstimestamps are usually better even for debug as welldebugging.
So for me Server (which is one instance) is created by main() and core, parser and logger are a tuple bornsthat is born and dies on per request (always together). Each tuple doesn't know the state or existence of other such tupletuples, and that is good so that arbitrary number of threads can be instantiated in parallel, (one thread per tuple) without loosinglosing scalability but preserving loose coupling.
Only thing is - it means you are not using any design pattern! But that's not a bad thing. It is not necessary that including a design pattern makes your design necessarily better.
Remember:
There are really rare reasons where using singleton becomes must; everywhere else, using singleton is always an invitation to problems.