Interface definition with no methods ?
Can an Interface definition have no methods at all ? Something like:
Public Interface IBlank
' Am Empty
End Interface
If possible, what do you think can be the use of such interfaces? On a first thought, it might not make sense to have these. But actually, empty interfaces can be very handy. Implementing an empty interface is like qualifying that class with an attribute or saying that it supports certain semantics.
The same thing can be achieved though custom attributes but it would be a kind of an overkill to inspect the type metadata to see if the type supports an operation as against the simple usage of the TypeOf operator. So, it is better (easier) to have something like:
Public Interface ISomeOperation
End Interface
Public Class MyType
Implements ISomeOperation
than have
<SomeOperation>
Public Class MyType
You can come across many such interfaces in .NET BCL. INamingContainer and ILogicalThreadAffinative are examples of such interfaces.
Wait. Don’t think that attributes are completely replaceable with empty interfaces. Attributes are a lot more powerful, just by the virtue of being able to take many more parameters. So, in my opinion, if an attribute has none other than True or False, Yes or No kind of values, then an empty interface is better (easier to use).