Hi,
I’m currently in the process of developing a domain model for a new application and have reached the stage where I need to define relationships with classes of different types that may perform the same role, and am confused as to the best way to define the relationship.
For example:
public class Car
{
public IDriver driver { get; set;}
public IPassenger passenger { get; set; }
}
public class Person : IDriver, IPassenger
{
}
public class Pet : IPassenger
{
}
In this case I want to be able to define that a diver of a car can be any class that implements IDriver and any passenger must implement IPassenger. In the case of a passenger it could be with a person or a pet. The interfaces in essence are defining the roles of each class.
What I want to understand is if in peoples opinions this is a good approach, or if the same thing could be accomplished using a different mechanism.