问题描述:

What is Interface implementation hiding in OOPS? What are the advantages?

Please can you help me by showing how to hide an interface implementation in C#?

网友答案:

Hiding implementation behind an interface = make your client class rely on an interface rather than implementation, i.e.:

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

class B { }

becomes

interface IB { }

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

class B : IB { }

The advantage of hiding the implementation is that you can change between different implementations and the client code doesn't change.

相关阅读:
Top