Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 951841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:47:59+00:00 2026-05-15T23:47:59+00:00

I have a user interface with a tree view on the left, and a

  • 0

I have a user interface with a tree view on the left, and a viewer on the right (a bit like an email client). The viewer on the right displays the detail of whatever I have selected in the tree on the left.

The user interface has “add”, “edit” and “delete” buttons. These buttons act differently depending on what “node” in the tree is selected.

If I have a node of a particular type selected, and the user clicks “edit”, then I need to open the appropriate edit dialog for that particular type of node, with the details of that node.

Now, there’s a lot of different types of node and implementing a visitor class feels a bit messy (currenty my visitor has about 48 entries….). It does work nicely though – basically for editing a have something like an OpenEditDialog class that inherits the visitor, and opens the appropriate edit dialog:

abstractTreeNode->accept(OpenEditDialog());

The problem is I have to implement the abstract visitor class for every “action” I want to perform on the node and for some reason I can’t help thinking I’m missing a trick.

The other way could of been to implement the functions in the nodes themselves:

abstractTreeNode->openEditDialog();

I’m ording the node around a bit here, so maybe this is better:

abstractTreeNode->editClickedEvent();

I can’t help but think this is polluting the node though.

I did think of a third way that I’ve not given that much thought yet. I could have a templated wrapper class that gets added to the tree instead which allows me to perhaps call free-functions to perform whatever actions, so I guess as it acts as a go between for nodes and interface:

(pseudo code off the top of my head just to give an idea):

template <class T>
TreeNode(T &modelNode)
{
    m_modelNode = modelNode;
}

template <>
void TreeNode<AreaNode>::editClickedEvent()
{
    openEditDialog(m_modelNode); // Called with concrete AreaNode
}

template <>
void TreeNode<LocationNode>::editClickedEvent()
{
    openEditDialog(m_modelNode); // Called with concrete LocationNode
}

etc..

So this is effectively extending the nodes but in a different way to using the visitor and it seems a little bit neater.

Now before I go ahead and take the plunge using one of these methods, I thought it’d be wise to get some input.

Thanks! I hope all this makes some sense..

EDIT:

I’ve mocked up the templated wrapper idea..

class INode
{
public:
    virtual ~INode() {}
    virtual void foo() = 0;
};

class AreaNode : public INode
{
public:
    AreaNode() {}
    virtual ~AreaNode() {}
    void foo() { printf("AreaNode::foo\r\n"); }
};

class RoleNode : public INode
{
public:
    RoleNode() {}
    virtual ~RoleNode() {}
    void foo() { printf("RoleNode::foo\r\n"); }
};

class ITreeNode
{
public:
    virtual ~ITreeNode() {}
    virtual void bar() = 0;
    virtual void foo() = 0;
};

template <class T>
class MainViewTreeNode : public ITreeNode
{
public:
    MainViewTreeNode() : m_node() {}
    virtual ~MainViewTreeNode() {}
    void bar() {}
    void foo() { m_node.foo(); }
protected:
    T m_node;
};

template <>
void MainViewTreeNode<AreaNode>::bar()
{
    printf("MainViewTreeNode<AreaNode>::bar\r\n");
}

template <>
void MainViewTreeNode<RoleNode>::bar()
{
    printf("MainViewTreeNode<RoleNode>::bar\r\n");
}

int _tmain(int argc, _TCHAR* argv[])
{
    MainViewTreeNode<RoleNode> role;
    MainViewTreeNode<AreaNode> area;

    std::list<ITreeNode*> nodes;
    nodes.push_back(&role);
    nodes.push_back(&area);

    std::list<ITreeNode*>::iterator it = nodes.begin();

    for (; it != nodes.end(); ++it)
    {
        (*it)->foo();
        (*it)->bar();
    }

    getchar();
    return 0;
}

Thanks.

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:47:59+00:00Added an answer on May 15, 2026 at 11:47 pm

    Visitor is useful when you have many operations and few types. If you have many types, but few operations, use normal polymorphism.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface like this: public interface IUser{ //some properties here T ToDerived(User
I have a client-side interface that allows the user to perform multiple edits against
I have user-interface where user can select grid column (like age) and operator (lesser
A lot of JavaScript libraries have user interface widgets. Usually they are created after
I have been developing an user interface with Java Swing, and I have met
I have to make a graphical user interface application using the language of my
I always have trouble designing the user interface when it come to manage a
I have a bunch of XML files I'm using for user interface and string
I have a fairly large application that uses WPF for its user interface. I
Is it good idea to have application engine written in c++ and user interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.