I'm designing a UI system, using classes, and am running into some complications trying to do everything I want to do. I'll try and explain my goals and such.
First, there's the base control, which everything inherits from. It contains pointers for linking it into a heirarchy tree (parent, child, next, prev). Next there's the window class, which always sits at the root of the tree. There's other classes too, such as a button class, slider class, etc. These all derive from the base control. Any object derived from the base class can appear in the tree.
Now, one goal I have is to have a layer of abstraction here, between the above classes, and a drawing implementation for each. So, for example, there's a button drawing class, which derives from the button class, and implements the render() virtual member function. The window drawing class derives from the window class, etc. This set of classes don't handle the functionality of the controls, only the rendering of them. So they are like a front-end basically. All the functionality is handled in the layer above.
So far, so good, but now I'm thinking about the checkbox type control, and think it should be derived from a button. The button would display as lit up if it's checked. It should display exactly like a regular button if off, and slightly different if on, so it makes sense to use common code here. Problem is, I don't know how to go about sharing it elegently. Button drawer is derived from button, which is derived from base. Checkbox would be derived from button, and a checkbox drawer would be derived from checkbox. I could have checkbox drawer and button drawer inherit from a second, common class, but code in that class couldn't access member data from the button class, since it wouldn't be derived from a button. That making any sense?
So, I wanted to see if anyone has any interesting ideas or anything. Remember, the non-drawer classes are abstracted from any drawing related code or member data. There is some new data I need in the button drawer class, btw, and so would need in the checkbox drawer too, since it's an extension of a button.
If no one understands what I'm talking about at all here, but you think you have the experience to maybe answer if you did, let me know and I'll see if I can't clarify more.