"backward" access in a class

Started by
11 comments, last by PopJimmy 22 years, 1 month ago
What are you intending to derive from Game? Any use of public inheritance models an "IS-A" relationship. You need to think to yourself whether that makes any sense. For example, you might be thinking of having a "Player" class derive from Game. It''s pretty obvious that Player IS-A Game is incorrect, so you would not model things that way.

--
Cats cannot taste sweets.
Advertisement
You may want to consider the Singleton design pattern. Essentially, a singleton is a class that is only instantiated once, and is globally accessable. They are very useful for things like graphics drivers, sound effects managers, etc.

So you''d write code like this:

  main(){Graphics::instantiate();Menu::Instantiate();SFX::Instantiate();Game::Instantiate();Game::Instance()->Run();}Game::Run(){Graphics::Instance()->DrawMenu(Menu::Instance()->GetMode());}  

This is a contrived example, but it''s the general idea of what you can do with singletons.
You can even include the instantiation in the Instance method. That way all objects will be automatically created on first use.

Kippesoep

This topic is closed to new replies.

Advertisement