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

  • SEARCH
  • Home
  • 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 592687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:45:57+00:00 2026-05-13T15:45:57+00:00

I have a hierarchical generic data structure. There is a root node and under

  • 0

I have a hierarchical generic data structure. There is a root node and under that there can be many tree nodes, or just a single data node, and tree nodes can have more tree nodes. A basic tree structure.

All data in my system is persisted in this format. I do however want to have a strongly typed interface to some of the different types of data that these data structures represent (ie. turn a generic hierarchical tree into a strongly typed address record).

I was planning on using an adapter pattern where I pass in a node to the adapter and it then exposes properties by interrogating the tree. This would also allow me to validate the tree (ie. that is has specific elements and that they have valid data in them). It also allows for extensibility (ie. the tree itself would also be exposed if there were additional data that was added at a later date).

Do you think this is the most optimal approach to achieve this or is there a simpler way?

Note: this is in C# and .Net 4.0.

Thanks!

  • 1 1 Answer
  • 2 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-13T15:45:57+00:00Added an answer on May 13, 2026 at 3:45 pm

    An Adapter is usually used to bridge between two incompatible interfaces. That doesn’t seem to be your problem here. In fact, I don’t really see any problem — as object languages are by nature hierarchical, you should be able to use a mostly 1-to-1 mapping between a class and a tree node.

    Perhaps by “Adapter” you just mean a class that wraps a Node or whatever particular Object type that describes your tree nodes, and I’d agree. There should be fairly obvious parent-child relationships that you can describe by having your node classes own or somehow return an array of child node/classes, and the attributes as getters/setters. Any needed validation could be done by the setters, or if need be during construction as a class inspects a given node and its child nodes. Something like the following:

    public class NodeFu {
    
        private Node node;
    
        public NodeFu(Node node){
            this.node = node;
            // perhaps traverse and validate node data here
        }
    
        public String getNodeAttribute(String attrName){
            // pardon the offense, Demeter, only for demonstration...
            return node.getAttributes().getNamedItem(attrName).toString();
        }
    
        public void setNodeAttribute(String attrName, attrValue){
            node.setAttributeValue(attrName, attrValue);
        }
    
        public ArrayList<NodeFu> getChildren(){
            ArrayList<NodeFu> children = new ArrayList<NodeFu>();
            for (Node childNode : node.getChildNodes()){
                children.add(new NodeFu(childNode));
            }
            return children;
        }
    } 
    

    I’m assuming you have more business logic to add to this class that will manipulate the data on the Node itself, otherwise the Node class would suffice and you could just use it directly.

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

Sidebar

Related Questions

I have some hierarchical data that I need display as a table, can I
I have an issue. I have hierarchical XML data such as: <Tree> <Node Text=Stuff
I have a hierarchical organization that is a tree where the node is a
I have a hierarchical data structure which, as far as I can see, needs
I have a hierarchical (tree structure) SQL Server table TEmployee with following columns Id
I have a hierarchical data that goes like this: +----------------------+-------+ | name | depth
I have a hierarchical data structure which I'm displaying in a webpage as a
I have some hierarchical data that I need to display in a series of
I'm working on a project where I have some hierarchical data that I want
For those Telerik gurus out there, I have a Hierarchical DataGrid that is created

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.