Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implement an interface with a private method in vb.net

I was kind of shocked by this. Could someone explain why this works? A good example of when to use it would also be nice.

Public Interface IFoo
  Sub DoIt()
End Interface

Public Class Bar
  Implements IFoo

  Private DoIt() implements IFoo.DoIt
End Class

...

Dim b as new Bar()
b.DoIt() 'error
CType(b, IFoo).DoIt() 'no error
like image 249
dotjoe Avatar asked Jan 12 '09 17:01

dotjoe


1 Answers

Having a private interface implementation basically just allows you to implement an interface without having to muddy your class' API. You can implement IFoo, but only APIs that treat you as an IFoo need to know that.

MSDN says

You can use a private member to implement an interface member. When a private member implements a member of an interface, that member becomes available by way of the interface even though it is not available directly on object variables for the class.

like image 92
bdukes Avatar answered Oct 02 '22 19:10

bdukes