Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Explicit implementation of interfaces are used to hide instance properties/methods unless the calling code excplicitly asks for the interface.</p> <p>This is useful in the following scenarios:</p> <ul> <li>The class author has deemed that the implementation of an interface is to be used in only rare cases and should be hidden by default for usability sake (this is clearly the case with the <em>Type</em> class as the explicit interface implementations are COM-specific)</li> <li>A class implements two or more interfaces that have common method/property signatures, but it's necessary to provide different implementations depending on the interface because the interfaces have implicit yet differing behavioral contracts beyond the method signatures (the <em>Type</em> class also has an example of this; presumably the implementations of _MemberInfo.GetIDsOfNames and _Type.GetIDsOfNames share the same signature, but do different things depending on whether you cast a <em>Type</em> instance to a _MemberInfo interface versus a _Type interface).</li> <li>This has been used (although is discouraged) to have a class implement IDisposable so that an instance of it can be used in a <em>using</em> block, yet encourage callers to use a more domain-specific method for "disposing" the class when calling the method directly. See <a href="http://blogs.msdn.com/b/kimhamil/archive/2008/03/15/the-often-non-difference-between-close-and-dispose.aspx" rel="nofollow">http://blogs.msdn.com/b/kimhamil/archive/2008/03/15/the-often-non-difference-between-close-and-dispose.aspx</a></li> <li>Can be use by API developers when they want a public class they're exposing to implement an interface of which the implementation should only be used within their assembly. In this case the interface would be declared with the <em>internal</em> keyword, and their public-facing class would explicitly implement the interface. The end result is that only code in their assembly can cast the instance of a class to the internal interface and access its implementation, while callers outside the assembly cannot.</li> </ul> <p>Those are the use cases that come to mind; I'm sure there are others I haven't listed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload