According to the article, it is suggested to not use a singleton. However, what is the alternative or better way? For example, in my GUI, I have a log window. After an operation, no matter where it is, I can easily record some information in the log window if a singleton is used. The singleton provides a shortcut, although via a global route. If not using singleton, any good way to do it? Note the operations may scatter anywhere. Thanks a lot!
Share
Do the simplest thing that could possibly work. In my experience, the simplest way to do logging is to use free functions.
Maybe the implementation is just a global, maybe its not. It doesn’t matter how you implement it. It only matters that they don’t write different code based on how it is implemented. Focus on the interface that is exposed.
IMHO, Singletons are bad because they are hard to change later. Not because of the way they are implemented, but because they tend towards interfaces that only allow for there to be a singleton behind it. That is hard to change. When change is difficult, then it costs a lot to maintain.