Tell me more ×
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. Current I figured out a design to do it as following

// 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? Thanks.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.