Original Post
Hi all, I've been designing a framework to encapsulate graphics related tasks such as providing a window to render to and handling image loading (I'm aware there are libraries available that already do this, but this is more of a learning exercise to see how things work than anything else). Anywho, I've come across a design issue with the window part that I can't seem to work out. At the moment, I have everything inside a Graphics namespace. Further, I have a Framebuffer class that represents the display device's physical framebuffer (e.g. color bits, depth bits etc. etc.) I then have a Device class to represent the display device itself (i.e. the graphics card). The Device class contains a Framebuffer and various methods to obtain display device information (e.g. name, display monitor, refresh rate). Now I have the Window class, which at the moment, contains a Device instance as well as other standard window attributes and handles. The way I designed all this was so that I could do something similar to the following...
Graphics::Window window;
// Display is a public Device instance inside the Window class
// Configuration is a public Framebuffer instance inside the Device class
window.Display.Configuration.ColorBits(8, 8, 8, 8);
// At the momment I can't do this, see below...
std::string deviceName = window.Display.Name();
window.Size(640, 480);
// etc. etc.
window.Initialize();
// ... As you can see I tried to make it as flexible as possible. The problem I'm having through is that the Device instance needs access to the Window class's window handle for retrieving display device information and I don't know how to expose it. If the handle is inside of the Window class the Device class can't access it directly. I considered putting the window handle inside the Device class but it didn't really make sense. This is really where I need help and my design falls to pieces :P (how can I "share" the window handle between the Device and Window, or would there be a better way to handle this?) Anyway, here are some other questions I have: 1. Is it bad design to expose public instances of the classes like this (I did this so I wouldn't be doing say window.Display().Name() [where Display() returns the instance] as it seemed easier and more logical in this case). 2. Although I'm just starting (and it might be hard to say), how do you think the overall design is looking? And would you recommend any changes? Sorry for the long winded post, and I hope it all made sense, but hopefully you read it and could offer some suggestions or design improvements which I would greatly appreciate. :)
