Skip to main content
gamedev.net
🔒 Locked

OOP Question

Started by Darkeye Dec 23, 2001 at 8:03 AM 0 replies 250+ views
Original Post
Darkeye
Darkeye
I am writing a series of basic modules, such as a logger and a timer. Each one is stored in a class and a source/header pair. I am trying to make it so that the different modules can co-exist together, or work independently, without any modification to the module source code. The problem is, for example, to use the logger module in the timer module, I would have to #include "logger.h", and thus the timer module would not compile unless logger.h is present, which I don''t want. Any ideas how I can acomplish this?
clabinsky
clabinsky
I have the same thought and have come up with some ideas without really trying all of them.

You could make some kind of generic interface. Maybe use a template function to call with any type. The template function could take a class or a type appropriate for doing its job.

The other case is is you want to log something like the time in through the logger class. Make a function in the time class that returns the information you need: getTimeTick(); The return value of this argument could be used as an argument in a function to the logger class like:

result=cLogger.Log(getTimeTick());

You could also make each class record informatiom about itself, like latest internal message char *szLatestMsg; Update this member variable when you need to. Other classes can check this through a function like szMsg=cTimer.GetMsg();

These might not be the most efficient or any good at all but they might give you ideas.
Why make it simple when you can make it sooo nice and complicated?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.