Thread: advanced problem

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    5

    advanced problem

    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.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The drawing classes (UI components) shouldn't be derived, they should be contained. Look at the design and implementation of the Java Swing library and its Look&Feel system, as you are trying to do something very similar.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sub-sum problem (NP)
    By stass in forum C Programming
    Replies: 2
    Last Post: 08-13-2008, 03:30 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM