INeedSomething 的更好名字...?
我试图为一个接口选择一个名称,通过它我可以将一些东西传递给一个对象,例如:
- 如果该对象是 INeedX 那么 SetX(some x) 方法将被调用;
- 如果对象是 INeedY 则 SetY(some y) 方法将被调用;
- 等等。 (很有趣,我知道:))
我尝试为这种接口找到一个不同的名称,但我无法弄清楚。
有人知道如何命名INeedSomething接口吗?
I was trying pick a name for an interface through which I can pass something into an object like:
- If the object is INeedX then SetX(some x) method will be called;
- If the object is INeedY then SetY(some y) method will be called;
- and so on. (funny as hell, I know :) )
I try to find a different name for this kind of interfaces but I can't figure this out.
Does anybody have an idea how to name the INeedSomething interface ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的界面的名称 IDependsOn 怎么样(又名:IDependsOnUserId、IDependsOnTimeOut)
What about the name IDependsOn for your interface (aka. IDependsOnUserId, IDependsOnTimeOut)
嗯,
INeed
界面可能表明设计很尴尬。在我看来,您真正寻找的是依赖注入,这相当于声明一个对象需要另一个对象才能运行的代码。因此,也许您真正想要的是
如果我是您,我会尝试看看上述内容是否适用于您的情况,这是声明需求/依赖项的更标准的方式
Well, the
INeed
interface is probably an indication of an awkward design. It seems to me that what you are really looking for is dependency injection, which is the code equivalent of stating that an object requires another object to function. So instead of having, maybe what you really want is
If I were you I would try to see if the above is applicable in your case, which is a more standard way of declaring needs/dependencies
通过使用泛型,接口传递的类型稍后定义,如下所示:
by using generics, the type passed by your interface is defined later, like this:
IRequire 听起来更好,但是,为此使用接口似乎是错误的。
使用属性代替:
IRequire sounds better, however, the use of the interface for this seems wrong.
Use attributes instead: