Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have a tree data structure, which is implemented with composite design pattern. I want to show it by a tree view in a GUI. By some event (such as double clicking a leaf in the tree view), a dialog corresponding to the data item is pop up to edit the item.

I currently figured out a design for it as follows:

// Data composite pattern.
class DataComponent {...};
class DataLeaf : public DataComponent {...};
class DataComposite : public DataComponent { vector<DataComponent*> m_vector; ... };

// Parallel GUI tree view composite pattern.
class GuiComponent
{
public:
    virtual void Edit(); // pop up a dialog to edit
};

class GuiLeaf : public GuiComponent
{
public:
    virtual void Edit(); // pop up a dialog to edit

private:
    DataLeaf* m_dataLeaf;
};

class GuiComposite : public GuiComponent
{
private:
    vector<GuiComponent*> m_vector;
};

Basically, the GuiLeaf has a reference of its data DataLeaf and a concrete implementation of the edit. Any suggestion or better way for the design of such kind of problems?

share|improve this question

closed as off-topic by Jamal Jul 20 at 17:30

If this question can be reworded to fit the rules in the help center, please edit the question.

    
This question appears to be off-topic because it is about a design review and there isn't much to review otherwise. Such questions are more fitting for Programmers. –  Jamal Jul 20 at 17:30

Browse other questions tagged or ask your own question.