Reputation: 21135
This is a follow-up to a previous question I had about interfaces. I received an answer that I like, but I'm not sure how to implement it in VB.NET.
Previous question:
Should this property be part of my object's interface?
public interface Foo{
bool MyMinimallyReadOnlyPropertyThatCanAlsoBeReadWrite {get;}
}
How can I achieve this with the VB.NET syntax? As far as I know, my only option is to mark the property as ReadOnly (I cannot implement the setter) or not (I must implement the setter).
Upvotes: 2
Views: 3692
Reputation: 34650
Simply define the getter in one interface, and create a second interface that has both the getter and the setter. If your concrete class is mutable, have it implement the second interface. In your code that deals with the class, check to see that it is an instance of the second interface, cast if so, then call the setter.
Upvotes: 2
Reputation: 580
In VB.NET I would implement it this way:
Public Interface ICanBeSecure
ReadOnly Property IsSecureConnection() As Boolean
End Interface
Public Interface IIsSecureable
Inherits ICanBeSecure
Shadows Property IsSecureConnection() As Boolean
End Interface
Upvotes: 1