What is the point of writing an interface without members ?
INamingContainer is one example in .NET Framework. And it's described in MSDN as :
Identifies a container control that creates a new ID namespace within a Page object's control hierarchy. This is a marker interface only.
Is it used for just this kind of blocks :
if (myControl is INamingContainer)
{
// do something
}
Or are there other advantages of it ?
EDIT : It was called Marker Interface Pattern (thanks Preet)
Memberless interfaces are used to provide mixin-like capabilities in C#. So given a class A:
class A : B { ... }
You can give it extra functionality (a-la multiple inheritance) by defining an interface IStuff:
interface IStuff {}
then 'implementing' it in A:
class A : B, IStuff { ... }
and then adding the extra features
class Methods {
public static void Something(this IStuff stuff) {
// some functionality here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With