Interfaces cannot declare types

As the error indicates, you just have to pull the definition of Status outside of the interface. I understand that it breaks encapsulation, but there's really no way around this. I suggest you change the name of Status to something which indicates a strong relation to Thing -- ThingStatus should do the trick.

enum ThingStatus { Accepted, Denied, Pending };

public interface Thing
{
    ThingStatus status { get; }
    etc...
}

Oh yes, the solution is to use an abstract class if you need such implementation. Abstract classes are not a bad design and are certainly useful in situations like this.

If you insist on using interfaces, I'm afraid you'd have to go with the solution from p.s.w.g and break a rule or two (those are just guidelines anyway, really).


abstract class and interface are different things. abstarct class is abstraction, higher than your domain model and interface is the contract (behavior) of your domain entity. You can use both in your solution as necessary. In concrete scenario status is not behavior it just state of entity. I think abstract class is more reliable choice.

Tags:

C#