"You can also get into trouble if people, usually unknowingly, try to access the renderer before it's ready or after it's been shutdown."
made me think you were not talking about singletons, which guarantee they are initialized when you use them, and shut down automatically ... ah, well ... sorry
quote:This can cause troubles, or at least some hassle, when you try to re-use your object class elsewhere. For instance, if you decide to make a stand-alone server to host your game on-line, then the object will still depend on a Renderer, even though you may not need to render anything in the server app. Or, maybe you decide to ditch your internal renderer and use some middleware graphics API. Oops! I bet they didn't derive their renderer from your Renderer base class. Now you need to re-work everything.
You have a perfectly valid point here. If that's how you plan to design your game, then the approach of passing a renderer interface as parameter might not be the best one. (Even though you would just need to include the interface definition for the renderer. You would never need to instantiate any renderers because you wouldn't be calling the render() method (which requires it) anyway.)
You can make your object not rendereable by it self. But then the object still has to provide some information that enables the system that will actually draw it to do it's job. You are again making dependencies. You just need to take care that the drawing system depends on an interface (that provides needed info), not on a (concrete) object class.
An object could also implement more than one interface to better divide the services it provides. It could implement an interface relevant to the rendering system and an interface relevant to the server-side system.
You will always depend on something - you just can't eliminate that. But when you DO depend, depend on an abstract interface instead on a concrete class.
quote:Or, maybe you decide to ditch your internal renderer and use some middleware graphics API. Oops! I bet they didn't derive their renderer from your Renderer base class.
That's not keeping you from making an adapter that implements the Renderer interface by using some X API (that's somehow what all engines more or less do). And I bet the "middleware graphics API" doesn't know anything about your Object class either.
quote:So again, the point I was trying to get at is that the Object shouldn't ever depend on any Renderer.
But then as I already said it ... the Renderer would have to depend on the Object. Which is cool - if you find it better that way. I'm just trying to show you, that you're not ending up with less dependencies. You just need to make them weak instead of strong (which relates to the singleton when you always end up making strong dependencies).
// edit:
The example I gave was from a 2d game that did just some trivial rendering. It's just an example, how you can avoid *singletons*. Sorry, again, for the misinterpretation.
p.s.: not arguing with you, just discussing the stuff ...
[edited by - jure on December 6, 2003 9:37:51 PM]