Given the hypothetical model below:
public abstract class Veiculo
{
public Motor Motor { get; set; }
}
public class Aviao : Veiculo { }
public abstract class Motor { }
public class MotorCarro : Motor { }
public class MotorAviao : Motor { }
Is it possible to restrict the type of Motor
to the Aviao
class as only MotorAviao
and its derivatives? Or, what would be the best solution for this scenario?
Edit
The same scenario, but with an attribute that is very common for cases of aggregation: a list of all aggregated objects on the other side of the relationship.
The Motor
class should know all vehicles that use it. It would look like this:
public abstract class Motor
{
public virtual ICollection<Veiculo> Veiculos { get; set; }
}