考虑以下抽象类:
我希望能够使用派生自LineContainer的类来重写抽象的CanBeGroupedWith方法,并使一切正常。这是否可行?
我希望能够使用派生自LineContainer的类来重写抽象的CanBeGroupedWith方法,并使一切正常。这是否可行?
public abstract class LineContainer
{
public abstract IEnumerable<Line3d> Get3dLines();
public abstract bool CanBeGroupedWith(LineContainer container);
}
public class DimensionContainer : LineContainer
{
public override IEnumerable<Line3d> Get3dLines()
{ //....etc
}
public override bool CanBeGroupedWith(DimensionContainer container)
{
/// I want this to be able to work with a DimensionContainer
/// parameter since the DimensionContainer is in fact
/// a LineContainer.
/// I want to be able to use the DimensionContainer as a
/// parameter because I want to make use of some specific
/// fields within it.
/// I originally tried to have the LineContainer class as a generic class
/// but I didn't know how to call it while still retaining the CanBeGroupedWith method.
/// I would then have to specify the type the type in a higher
/// level class i.e. LineContainer<DimensionContainer> which is
/// defeats the purpose of the higher level function?
/// Any assistance much appreciated
}
}
需要帮助或协助/建议将不胜感激