Reputation: 1302
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
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