TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  7@610Checked automatically with code checker

This rule is Obsolete
Synopsis:Use explicit interface implementation only to prevent name-clashing or to support optional interfaces
Language:C#
Severity Level:5
Category:Object oriented


Description:

When you use explicit interface implementation, then the methods implemented by the class involved will not be visible through the class interface. To access those methods, you must first cast the class object to the requested interface.

It is recommended to use explicit interface implementation only:

  • When you want to prevent name clashing. This can happen when multiple interfaces must be supported which have equally named methods, or when an existing class must support a new interface in which the interface has a member which name clashes with a member of the class.
  • When you want to support several optional interfaces (e.g. IEnumerator, IComparer, etc) and you do not want to clutter your class interface with their members.

Consider the following example.

public interface IFoo1
{
 	void Foo()
}
public interface IFoo2
{
 	void Foo()
}
public class FooClass : IFoo1, IFoo2
{
 	// This Foo is only accessible by explictly casting to IFoo1
	void IFoo1.Foo() { ... }
	
 	// This Foo is only accessible by explictly casting to IFoo2
	void IFoo2.Foo() { ... )
}