隐藏在接口后面的实现=使您的客户端类依赖于接口而不是实现,即:
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)
隐藏实现的优点是您可以在不同的实现之间进行更改,并且客户端代码不会更改.