#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    3
    Rep Power
    0

    Question design pattern for creating trees?


    Hello,
    I have a Java class I just wrote that reads like C-code and I am hoping someone can suggest a design pattern that would help me make things more object-oriented (and hopefully more maintainable).

    The information I am working with is hierarchical in nature. The class needs to generate a small number of trees. We start with a small collection of strings we get from a static mapping file, then for each name do a database lookup to find out what the node names are for the next level. We continue for each level. When you hit a leaf node, the unique names that identify the root->leaf path form a key you can use to lookup if an item is in a database.

    In pseudo-code we have

    for each item in Collection ca {

    }
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    3
    Rep Power
    0

    the rest of tree design pattern inquiry


    Sorry! I hit the wrong key sequence and sent an incomplete message. Here's a complete post.

    Hello,
    I have a Java class I just wrote that reads like C-code and I am hoping someone can suggest a design pattern that would help me make things more object-oriented (and hopefully more maintainable).

    The information I am working with is hierarchical in nature. The class needs to generate a small number of trees. We start with a small collection of strings we get from a static mapping file, then for each name do a database lookup to find out what the node names are for the next level. We continue for each level. When you hit a leaf node, the unique names that identify the root->leaf path form a key you can use to lookup if an item is in a database.

    In pseudo-code we have


    // build the tree
    for each item in collection a {
    get collection b
    for each item in collection b {
    get collection c
    for each item in collection c {
    // keep going until we get to leaf nodes,
    // which are always at the same level
    }
    }
    }

    // get the info for each "key" we generate from traversing each
    // leaf-to-root path of the tree we generated.
    generate keys
    for each key, lookup item in database, record its status

    How would a Java expert code this? Is there a specific pattern the OO experts use? This must have been done many times before, for instance for dynamically generating hierarchical trees for navigation menus...

    Thanks for any pointers,
    C.J.

IMN logo majestic logo threadwatch logo seochat tools logo