c# - 没有任何成员的接口(interface) - 不好的做法?

标签 c# interface

<分区>

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/

相关文章:

interface - Golang 接口(interface)转换为嵌入式结构

c# - 在多个类中继承相同接口(interface)的问题

c# - WCF REST - 覆盖传入的请求数据

c# - 将多个复选框值传递到模型 .net mvc 的更深层次

c# - 将WPF与MVVM架构一起使用以创建与要轮询的设备相对应的动态GUI

c# - 如何将 EnumConverter 与 CsvHelper 一起使用

c# - .net 应用程序对象提升为第 2 代

json - Golang interface{} 类型误解

c# - 具有多态性的通用接口(interface)来处理对象

VBA:有类似抽象类的东西吗?