Sign in to follow this  
caldiar

Header Files & Virtual Functions

Recommended Posts

So I just hooked my computer back up after a few months since I'm moving. I haven't moved yet but I was getting impatient and wanted my computer back. Anyways, I opened up some old code I was writing and when I looked at a few files I had a wtf moment. The files are organized like this: Header Folder - Renderer: Manager.h Graphic_Manager.h Texture_Manager.h Geometry_Manager.h Model_Manager.h Source Folder - Renderer: Graphic_Manager.cpp Texture_Manager.cpp Geometry_Manager.cpp Model_Manager.cpp Now, I looked at the Manager.h file and in short its just some simple basic functions like Load(), Unload(), Purge(), Init(), etc.... and they're all virtual. Ok, no big deal. But I take a look at the rest of the _Manager.h files and they derive themselves from the Manager.h file with all the virtual functions. I say to myself "That's kinda silly. Manager.h doesn't actually do anything. It doesn't actually execute any functions. It doesn't manage anything. So why inherit from it?" There's really no point in inheriting from virtual functions when the virtual functions don't even do anything. I don't need to make the child classes behave differently than the parent because the parent doesn't even have any functionality! I figure I could just get rid of Manager.h and have all of the other classes just be parents. The reason I'm posting this is because I fail to see what possible reason I could have for even writing the files like this. If anybody might actually see some reasoning to my thought process I would appreciate hearing it. I'm having a hard time getting back into the groove of programming. =( Thanks for taking the time to read this. I look forward to hearing back from you.

Share this post


Link to post
Share on other sites
The base class provides a common interface, which can be used by other functions to manipulate the objects. For instance, you might want to implement:

void UnloadAll(Manager & m, std::list<std::string> resources) 
{
for(std::list<std::string>::iterator it = resources.begin();
it != resources.end(); ++it)
{
m.Unload(*it);
}
}


This has the advantage of being usable for any manager. Of course, unless you actually need several different objects to be usable by another in this way, don't add a base class.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this