java - Location hierarchy data structure -


data structure or data model location hierarchy

i have following location types,  airport city state country  hierarchy country has state, state has city , city has airport.  city:san francisco city:frankfort    rate 100$ stored in system in form. 

when person ask rate airport:sfo airport:fra, application should rate available airport:sfo airport:fra.

as don’t have one(we have city city), application should check 1 level higher airport city. application should able find city of airport:sfo , city of airport:frankfort , check whether rate available. in case picks 100$ city:san francisco city:frankfort rate maintained 100$.

how can represent location hierarchy in data structure (in java)? graph or tree useful? if can please provide me samples.

imo, there 2 ways bottom-up or top-down (though both based on has-a relationship:

bottom-up:

1, have classes airport, city, state , country

2, airport have city, city have state, state have country variable

now whenever want rates, goto airport object, check city->state->country etc , charge accordingly

top-down:

1, have classes country, state, city, airport

2, country have list containing state, state have list of city , city have airport list

i prefer 1st one, since maintaining 1 value of parent easier/efficient maintaining list of children.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -