Home > database >  what is the usage of a marker interface that inherit from another interface?
what is the usage of a marker interface that inherit from another interface?

Time:08-02

for example:

public interface ITagHelper : ITagHelperComponent
{
}

I understand ITagHelper is used as a marker interface which doesn't contain any member, but since it inherits from ITagHelperComponent, then why not just use ITagHelperComponent as a marker interface directly? what's the point to have one extra layer of abstraction?

CodePudding user response:

You want to mark a class, but it should also implement some behavior. Though, marker interfaces are usually a code-smell.

CodePudding user response:

There might be types that implement ITagHelperComponent but should be excluded when finding types that are marked with ITagHelper. If you use ITagHelperComponent directly as your marker interface, you loose this option.

  • Related