问题描述
我最近遇到了一种情况,我希望将一组类传递给一个方法(这样该方法将一个接口作为参数).
I recently came across the situation where I wanted a set of classes to be passed into a method (so that method took an interface as a parameter).
但是,接口下的类每个都有不同数量的方法,所以接口本身是空白的.
However, the classes under the interface each had a different number of methods, so the interface itself was blank.
如果有的话,这对我的应用程序的设计有什么看法?在这种情况下,我打算使用一个抽象类,但我一直使用接口,所以可能有些东西阻止了我使用抽象类(不记得是什么).
What, if anything, does this say about the design of my application? I was going to use an abstract class in this case, but I kept with interfaces so something probably stopped me from using abstract classes (can't remember what).
语言:C#(尽管这与语言无关).
Language: C# (though this is independent of the language).
推荐答案
您所描述的是标记界面".
What you've described is a 'Marker Interface'.
http://en.wikipedia.org/wiki/Marker_interface_pattern
与任何设计模式一样,只要它是适合手头任务的正确模式,它就没有本质上的好坏之分.
As with any design pattern, there's nothing inherently good or bad about it as long as it is the right pattern for the task at hand.
这篇关于定义一个空白的接口及其含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!