Consider the following classes:
public abstract class Planet
{
protected abstract Material Composition { get; }
}
public abstract class TerrestrialPlanet : Planet
{
protected override Material Composition
{
get
{
return Type.Rocky;
}
}
}
public abstract class GasGiant : Planet
{
protected override Material Composition
{
get
{
return Type.Gaseous;
}
}
}
Is there a way to prevent the inheritance of a non-abstract object directly from the class Planet?
In other words, can we ensure that any class that directly inherits from Planetis abstract?
public class Earth : TerrestrialPlanet { ... }
public abstract class IcyPlanet : Planet { ... }
public class Pluto : Planet { ... }
Chris source
share