Edit:. The following values ββare the same for the get / set properties, so the fact that you cannot declare fields in an interface is not fundamental to the points I make.
In your case, ITimeEvent.Handler is a field, which means you can do the following:
ITimeEvent x = ...; IJobTimeEventHandler handler = ...; x.Handler = handler;
If x was assigned an object (specific) of type JobTimeEvent , and JobTimeEvent.Handler was declared as JobTimeEventHandler , the assignment above failed. This is an example of how contravariance is not a safe operation to assign.
If instead you had the following:
interface ITimeEvent { IJobTimeEventHandler Handler { get; } }
Then you can easily do this:
class JobTimeEvent : ITimeEvent { private JobTimeEventHandler _handler; public IJobTimeEventHandler Handler { get { return _handler; } } }
source share