Pankesh Patel
Pankesh Patel

Reputation: 1302

representing hierarchical relationship

Can you suggest me "How can I represent the hierarchical relationship through java class?" you are welcomed to suggest other techniques.

For instance, User specifies that

       "Room" belongs-to "Floor" and  "Floor" belongs-to "Center"

I want to represent this relationship as Java class, and later want to retrieve this relationship.

-Pankesh

Upvotes: 0

Views: 275

Answers (1)

J Barclay
J Barclay

Reputation: 491

What you're talking about is standard object composition

'Belongs-to' and 'contains' are rather similar here. So for example:

public class Center
{
   private List<Floor> floors;
   ...
   public List<Floor> getFloors()
   {

      return this.floors;
   }
}

public class Floor
{
   private List<Room> rooms
   ...
}

public class Room
{
   private String roomNumber;
   ...
} 

Upvotes: 2

Related Questions