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.