There is a time where using globals too much can make it a pain to debug, but for a simple logger, it won't be too difficult to debug, especially when it's purpose is to help you debug
Structure of classes in good Game Engine?
#41 Members - Reputation: 158
Posted 21 June 2012 - 09:45 AM
There is a time where using globals too much can make it a pain to debug, but for a simple logger, it won't be too difficult to debug, especially when it's purpose is to help you debug
#42 Members - Reputation: 312
Posted 21 June 2012 - 10:05 AM
Looks rather useful, and not just as a static variable.I found the service locator pattern (as described here http://gameprogrammi...ce-locator.html) a good alternative to the singleton. Its still very global but not that restrictive anymore.
#43 Members - Reputation: 337
Posted 21 June 2012 - 05:01 PM
- Passing some semi-global application class around is just hugely increasing dependencies since now you don't know which objects a class will look up through the application class (the service locator anti-pattern).
#44 Members - Reputation: 1528
Posted 21 June 2012 - 05:21 PM
MyLogger::log(std::ostream& stream, const std::string& what);
Done.
#46 Members - Reputation: 556
Posted 22 June 2012 - 04:51 PM
http://martinfowler.com/articles/injection.html
#47 Members - Reputation: 923
Posted 24 June 2012 - 11:30 AM
I found the service locator pattern (as described here http://gameprogrammi...ce-locator.html) a good alternative to the singleton. Its still very global but not that restrictive anymore.
Cygon mentioned it as a anti-pattern though..
- Passing some semi-global application class around is just hugely increasing dependencies since now you don't know which objects a class will look up through the application class (the service locator anti-pattern).
I had to laugh
Yep, it's widely considered an anti-pattern because the service locator is the equivalent of handing your classes a big box of other objects and letting them go shopping in it.
The dependencies are turned completely opaque since all you see from the outside is a constructor taking a (ServiceLocator &) -- you have to rely on the documentation or consult the code to find out what dependencies a class really has. And those may change at any time. Missing dependencies (common scenario: component X adds a new dependency) result in an error at runtime if and when the code consuming the dependency is reached because the compiler can't determine if the service locator will have the required service when it is looked up. Such classes also become dependent on the service locator implementation (whereas dependency injection can happen without the knowledge of the partaking classes, see sauce for an example).
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.






