What is the best practice for specifying which classes are allowed to be stored in a class property? For example if I had a DTO with a property that should allow ClassA, ClassB, ClassC, another property that allows ClassC, ClassD, ClassE, another property that allows ClassA, ClassC, ClassE, how should I define these classes? For example,public class MyDto{    public Vehicle Vehicle { get; set; }    public Machine Machine { get; set; }}[Vehicle][Machine]public class Car { }[Vehicle][Machine]public class Plane { }[Machine]public class Robot { }UPDATEIf possible I'd like to avoid using marker interfaces since this is considered a code smell?
How do I restrict specific classes for a property?
object oriented;object oriented design
You would define an interface which is implemented by the set of classes which you will allow, and then set the type of the property as that interface.Presumably the classes in question have some interface in common. If they have nothing in common, then the real question is why you want to store unrelated objects in the same property. Marker interfaces are indeed considered a code smell, but a code smell is (according to wikipedia): any symptom in the source code of a program that possibly indicates a  deeper problemSo the marker interface are not the problem you have to work around. Rather, they indicate you have a deeper problem, which is indicated by your need to store unrelated objects in the same slot.  