• Advertisement
Sign in to follow this  

global pointer for direct3d device?

This topic is 2897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In a book i've been reading, they create an Engine class that has a direct3d device. The Engine class also has an extern global Engine pointer. This way the the direct3d device doesn't have to be passed into every class that needs it as long as the Engine.h header file is included in the class. Is this a good thing to do or should I just pass the device into classes as needed? What are the pros and cons to this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
It is preferable, from a design sense, to pass the object to whatever interfaces require it. This makes dependencies explicit and aids in modularization/isolation, which in turn improves reusability, maintainability, and testability of code. It forces you to make a conscious choice about where and when you pass the dependency (the D3D device) and whether it is actually correct and necessary to do so, or if the underlying design you are following is flawed.

The book is likely using a global approach because either (a) it is a bad book, or (b) it is not a book that is aimed to be about design issues, but rather a demonstration of how to use D3D. The latter is slightly more forgivable. The method of using a global pointer is valid and will function, but is suboptimal for scale.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement