.NET 代码第一个纬度经度接口



我正在开发一个 VB.NET 代码优先的数据库。我想将纬度和经度添加到位置和邮政编码中。现在我正在为每个类添加一个地理坐标。

Public Interface ILocation
    Property Street As String
    Property City As ICity
    Property State As IState
    Property Postal_Code As IPostalCode
    Property Country As ICountry
    Property Coordinate As IGeographicCoordinate
Public Interface IPostalCode
    Property ZIP As String
    Property Time_Zone As ITimeZone
    Property Coordinate As IGeographicCoordinate
Public Interface IGeographicCoordinate
    Property Latitude As Decimal
    Property Longitude As Decimal

我的问题是,让位置和邮政编码继承地理坐标接口会更好吗? 我认为使用我当前的实现,我将拥有一个带有两个外键的地理坐标表(对于其他对象可能更多(。 如果我使用听觉实现,我可以找到任意两个 IGeographicCoordinate 类之间的距离......

Public Function Distance(byval LHS as IGeographicCoordinate, _
    byval RHS as IGeographicCoordinate)

使用听觉实现会将两个实体捆绑在两个IGeographic坐标的实现中。 我也可以让这些类继承地理坐标类......

Public Class Location
    Inherits GeographicCoordinate
    Implements ILocation

我倾向于远离做这样的事情,因为我被锁定在没有任何带有 lat 和 long 继承其他任何东西的类。

谢谢。

我喜欢你已经拥有它的方式。 除非由于某种原因您很难将这些实体读取和写入数据库(这不应该如此(,否则我认为这为您提供了最大的灵活性。 如您所说,如果在邮政编码和位置上实现接口,则无法轻松提供与坐标相关的功能。 如果你继承,你就限制了你从其他类继承的能力。 因此,如果其他两个选项都有缺点,而您提出的想法没有,为什么不使用它呢? 除非你能想到一些你没有提到的缺点?

最新更新