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

put on hold as off-topic by Jamal yesterday

  • This question does not appear to be a code review request within the scope defined in the help center.
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 yesterday
add comment

Browse other questions tagged or ask your own question.