我有以下情况:C#抽象基类 - 延长实施
public class GeoLocation
{
public double Longitude { get; set; }
public double Latitude { get; set; }
public string LocationName { get; set; }
}
public abstract class Base
{
public abstract GeoLocation GeoLocation { get; set; }
}
public class Concrete : Base
{
public override GeoLocation GeoLocation
{
get;
set;
}
}
现在,如果我创建了一个类Concrete2
从Base
继承,以及和我想的GeoLocation
对象有1个以上属性:
public string Address{ get; set; }
什么是最好的实施方式?
我可以创建一个名为GeoLocationEx : GeoLocation
新类,并存在,但然后将Address
财产在我Concrete2对象,我将有2个属性:GeoLocation
和GeoLocationEx
我不喜欢......
我也可以使Geolocation类部分,并将其与Address
属性为Concrete2
类延伸,但我不知道这会是一个“正确”使用部分类。
什么能做到这一点的最好方法是什么?
在此先感谢您的帮助!
'GeoLocation'对象?在这种情况下,如果您想通过'Base'界面使用Concrete2'对象,则必须检查它是否是Concrete2'对象,而不是'Concrete',并且只有传入'GeoLocationEx'对象。 – 2012-04-22 14:29:28
为什么不能简单地将“地址”添加到GeoLocation对象? – 2012-04-22 14:30:39
我找到了解决办法看这个帖子: 抽象类请求其中T:参数{ -t参数; } 类专门:请求 { } –
2012-04-22 14:47:37