vb.net用不同的接口实现策略模式
是否可以在VB.net中实现具有不同参数的策略模式? 例如,我有以下代码:
Public Interface InterfaceDataManipulation
Sub updateMyData()
End Interface
如何在使用不同参数实现上述接口类的类中实现 updateMyData,例如在类 x 中:
Public Class X
Implements InterfaceDataManipulation
Public Sub updateMyData(ByVal x as String)
Console.Writeline(x)
End Sub
End Class
但是 IDE 会引发错误“类 x 必须在接口 InterfaceDataManipulation 上实现 updateMyData”
is it possible to implement strategy pattern with different parameters in VB.net?
For example I have the following code:
Public Interface InterfaceDataManipulation
Sub updateMyData()
End Interface
How to implemente updateMyData in the class that implements above interface class with different parameter, for example in class x :
Public Class X
Implements InterfaceDataManipulation
Public Sub updateMyData(ByVal x as String)
Console.Writeline(x)
End Sub
End Class
But the IDE raises an error "class x must implement updateMyData on interface InterfaceDataManipulation"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过添加参数,您并没有实现接口 - 接口的想法是人们只需了解接口即可使用您的类 - 因此您的带有参数的子将不符合他们的期望。
给这只猫剥皮的方法可能有很多,但以下是其中一些选项:
By adding a parameter you're not implementing the interface - The idea of the interface is that people can use your class by only knowing about the interface -so your sub with parameter wouldn't match their expectations.
There are probably many ways of skinning this cat, but these are a few of the options:
方法签名需要附加其在接口中实现的方法,如上所示。
The method signature needs to be appended with the method it is implementing in the interface as show above.