4

I have recently started working with C# and NHibernate so all this is quite novice to me.

In the application I'm building I need to calculate distances between UK postcodes. One of the approaches is to use grid reference and Pythagoras distance. Another approach is to use Google Maps to get distances.

I have an interface Ipostcode with method getDistance(IPostcode p) and depending on implementations classes will be talking to different tables.

For Grid References I'll have GridRefPostcode object and DB table: (string)postcode, (long)northing, (long)easting.

For Google Maps I'll GoogleMapsPostcode object and DB table: (string)postcode, (string)otherPostcode, (double)distance.

Class Person will have a field IPostcode, and then I'll be calculating distances based on getDistance() provided by both classes.

Now the question is: How to map this class-relationship in NHibernate? How I can fit interface into mapping?

                   Person
                      ^
                      |
                  IPostcode ( Interface )
                   ^     ^
                   |     |
      GridRefPostcode    GoogleMapsPostcode

Is it even possible? I have a gut feeling that my class structure needs to be changed completely, but this seems to be the most reasonable solution: If I have distance between 2 postcodes provided by Google, I use it, if it is not available, I step down to GridReferences.

Any ideas are highly appreciated!

trailmax
  • 34,305
  • 22
  • 140
  • 234

0 Answers0