I’m working on a little project that has some subsystems like sound and image and such. So each subsystem is a singleton in the application cause there only needs to be a single sound or image subsystem. The problem I have in some circumstances I don’t need both subsystems available so one of them may not actually exist. While that’s fine, I just return null when I request a pointer to the subsystem, the problem I have is that I need to check in every function that in fact that subsystem exists because I’m still able to call methods of that none existing subsystem which leads to crashes. Is there any way to make all those calls to the non-existing subsystem just return null without doing anything? In code what I do right now is checking that the subsystem I want to use exists every time I want to use it which has a performance cost.
And I just want to make the calls and return null every time without having to check that my subsystem exists every time I make a call to that subsystem. The only way I can think of doing that involves creating like a null version of each subsystem but that would take time to write and code I don’t really want to see in my little project. I hope you can help me.Code:if(myApp::getSoundSubsystem()) { // We know the sound sybsystem exists, use it. }
Thanks in advance.