Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 接口和继承:从依赖注入类访问继承的方法_Vb.net_Oop_Inheritance_Interface - Fatal编程技术网

Vb.net 接口和继承:从依赖注入类访问继承的方法

Vb.net 接口和继承:从依赖注入类访问继承的方法,vb.net,oop,inheritance,interface,Vb.net,Oop,Inheritance,Interface,以下是我的设想: Public Interface IFlow End Interface Public Class Base Protected _var1 as String Protected _var2 as String Public Property Item(str As String) As String... Public Function Func() As String... End Class Public Class MyFlow Inh

以下是我的设想:

Public Interface IFlow
End Interface

Public Class Base
   Protected _var1 as String
   Protected _var2 as String

   Public Property Item(str As String) As String...

   Public Function Func() As String...
End Class

Public Class MyFlow
Inherits Base
Implements IFlow
...
End Class

Public Class ServiceCaller
   Private _flow As IFlow
   Public Sub New(ByVal flow As IFlow) 
     _flow = flow
   End Sub

   Public Function Test() As String
     _flow.Func() <--- Can't call this
   End Function
End Class
公共接口IFlow
端接口
公共阶级基础
受保护的_var1作为字符串
受保护的_var2作为字符串
公共属性项(str作为字符串)作为字符串。。。
公共函数Func()作为字符串。。。
末级
公共类MyFlow
继承基础
工具IFlow
...
末级
公共类ServiceCaller
私有流如下图所示
公共子新建(ByVal流为IFlow)
_流量=流量
端接头
作为字符串的公共函数Test()

_flow.Func()我建议采用以下方法,而不是将方法添加到多个接口中:

  • 使用常用方法创建一个基本接口
  • 使用
    Inherits
    关键字从基本接口派生出需要通用方法的接口
  • 在基类中实现基类接口
  • 您不需要在派生类中再次实现这些方法。但是,如果您将基类中的实现标记为Overreable,那么如果您需要更改派生类中的实现,就可以重写派生类中的方法

这样,您就不需要将方法添加到多个接口中,也不需要再次将调用传递给每个类中的基类实现。

一旦我按照您的解释阐述了这一点,这就非常有意义了。谢谢