隐藏在OOPS中的接口实现

Tho*_*mas -1 c# oop

隐藏在OOPS中的接口实现是什么?有什么好处?

请问您能否通过展示如何在C#中隐藏接口实现来帮助我?

Wik*_*hla 5

隐藏在接口后面的实现=使您的客户端类依赖于接口而不是实现,即:

class A {
   // make use of B somehow
   void Foo( B b )
}

class B { }
Run Code Online (Sandbox Code Playgroud)

interface IB { }

class A {
   // hide the implementation behind an interface
   void Foo( IB b ) { }
}

class B : IB { }
Run Code Online (Sandbox Code Playgroud)

隐藏实现的优点是您可以在不同的实现之间进行更改,并且客户端代码不会更改.