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 8513359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:32:39+00:00 2026-06-11T04:32:39+00:00

I have a hierarchical structure of objects (lets say, 3 levels). Class A is

  • 0

I have a hierarchical structure of objects (lets say, 3 levels).

Class A is composed with class B, class B with class C.

The initialization does something like :

$a1 = new A()
$a1->add('B1', $b11 = new B())
$a1->add('B2', $b12 = new B())
$b11->add('C1', $c111 = new C())
$b12->add('C1', $c121 = new C())
...

My problem occurs when $c121 wants to retrieve $c111. I currently know 2 ways to achieve that :

1/ Assume that A is a singleton : it gives me the ability to dash back to the root from any node of the tree. I can then address any node from the root with a full “pathname”.

2/ Give to each object its ancestor, so they can go back (by ancestor reference) and forth (by pathname) through the tree.

While both serve my needs, I can’t find any of those solutions satisfying.

Am I missing something ? This should be a common problem, yet I can’t figure out what design pattern could match this issue.

EDIT Note that the hierarchy isn’t composed of similar items. So it is a fixed hierarchy. Only the quantities of items at each level is fluctuating. (eg. Clients, Orders and Products Ordered)

  • 1 1 Answer
  • 0 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-06-11T04:32:40+00:00Added an answer on June 11, 2026 at 4:32 am

    If your classes are disparate, then I’d treat them as such (ie you don’t have a tree per se).
    It seems like you’re trying to treat the disparate elements as if they were somehow similar.

    If you need access to a containing class (what you’re calling parent), you will need to provide a reference.

    In your example above, I would give your associated objects a reference to object “holding” it, and give the C class a means to get its siblings.

    $c121=new C(this);   // pass reference to container
    $c121->getSiblings();  // method to get sibling through reference to containing object
    

    Another way to look at that is:

    $frank=new Customer()
    $frank->add('Order01', $order1 = new Order())
    $frank->add('Order02', $order2 = new Order())
    $order1->add('LineItem01', $item1 = new LineItem())
    $order1->add('LineItem02', $item2 = new LineItem())
    
    $order1->getOrder() //return collection
    $order1->getOrder()->getItems() //return collection items/siblings
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an hierarchical structure of classes like this public class Class1 { internal
I have a hierarchical class structure like this: Category -> Template -> Instance A
I have a hierarchical table on Oracle pl/sql. something like: create table hierarchical (
i have a table with hierarchical structure. like this: (source: aspalliance.com ) and table
I have a hierarchical list of objects. Assume that the structure is as follows:
I have a hierarchical structure and when the user press on Add a child,
I'm looking to have a hierarchical class structure in which a level of controller
I have a requirement to represent a hierarchical structure in a class within c#.
I have a data structure that looks like this: public class Node { public
I have a hierarchical (tree structure) SQL Server table TEmployee with following columns Id

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.