<分区>
Possible Duplicate:
What is the purpose of a marker interface?
创建一个完全空的界面是否是一种不好的做法,例如:
public interface ISomething
{
}
在某些情况下,我希望以不同于其他对象的方式对待某些对象,但我不需要任何新行为。
<分区>
Possible Duplicate:
What is the purpose of a marker interface?
创建一个完全空的界面是否是一种不好的做法,例如:
public interface ISomething
{
}
在某些情况下,我希望以不同于其他对象的方式对待某些对象,但我不需要任何新行为。
最佳答案
我个人认为空接口(interface)不是什么好事。
接口(interface)旨在描述行为契约。一个空接口(interface)不描述任何行为——您没有在此处定义任何形式的契约。
design guidelines for interfaces具体说:
Avoid using marker interfaces (interfaces with no members).
Custom attributes provide a way to mark a type. For more information about custom attributes, see Writing Custom Attributes. Custom attributes are preferred when you can defer checking for the attribute until the code is executing. If your scenario requires compile-time checking, you cannot comply with this guideline.
关于c# - 没有任何成员的接口(interface) - 不好的做法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3310936/