Support Protected Members in Interfaces

By Michael Flanakin @ 10:49 AM :: 196 Views :: 0 Comments :: (Open), .NET, (Reported) :: Digg it!

I thought I mentioned this before, but I guess not. I really want to have the ability to create an interface which has protected members. An interface is all about forming a contract with consumers, right? Well, isn't a child class a consumer? I'd argue that it is. An example of what I'm looking for might be an interface for a domain object. I want everyone to get the id, but only want the class itself to set it. Another instance might be in a situation where you'd need to execute some method internally, like validate prerequisites for an event or something like that (see below). I typically need something like this when I want to enforce a standard implementation across the board.

public interface ICommand
{
    public long Id { get; protected set; }
    protected bool ValidatePrereqs();
}

Reported @ http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=291006

Edit: Looks like this is "being considered" for a future release. Not sure what that means, but we'll see.

Edit: Well, I guess "being considered" doesn't mean a whole lot. The idea was pretty much shot down by someone on the C# team. I feel like I didn't explain my point well enough; however, I understand his point. Essentially, protected members can only be accessed by child classes, so what's the point in having an interface member for a class that knows about its members? Sure, that makes sense, but that doesn't mean I don't want the capability. I guess I like it more for standardization than anything.

Ratings

Comments

Currently, there are no comments. Be the first to post one!
Click here to post a comment



Archives Archives

Categories Categories

Related Links Related Links