Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 20 Interfacesprevious at this levelnext at this level 20.4 Interface implementationsprevious at this levelnext at this level 20.4.2 Interface mapping Paragraph 11 A class or struct must provide implementations of all members of the interfaces that are listed in the base class list of the class or struct. 2 The process of locating implementations of interface members in an implementing class or struct is known as interface mapping. Paragraph 21 Interface mapping for a class or struct C locates an implementation for each member of each interface specified in the base class list of C. 2 The implementation of a particular interface member I.M, where I is the interface in which the member M is declared, is determined by examining each class or struct S, starting with C and repeating for each successive base class of C, until a match is located: Paragraph 31 A compile-time error occurs if implementations cannot be located for all members of all interfaces specified in the base class list of C. 2 Note that the members of an interface include those members that are inherited from base interfaces. Paragraph 41 For purposes of interface mapping, a class member A matches an interface member B when: Paragraph 51 Notable implications of the interface-mapping algorithm are: [Example: In the example
interface ICloneable  
{  
   object Clone();  
}  
class C: ICloneable  
{  
   object ICloneable.Clone() {...}  
   public object Clone() {...}  
}  
the ICloneable.Clone member of C becomes the implementation of Clone in ICloneable because explicit interface member implementations take precedence over other members. end example]
Paragraph 61 If a class or struct implements two or more interfaces containing a member with the same name, type, and parameter types, it is possible to map each of those interface members onto a single class or struct member. [Example: For example
interface IControl  
{  
   void Paint();  
}  
interface IForm  
{  
   void Paint();  
}  
class Page: IControl, IForm  
{  
   public void Paint() {...}  
}  
Here, the Paint methods of both IControl and IForm are mapped onto the Paint method in Page. It is of course also possible to have separate explicit interface member implementations for the two methods. end example] Paragraph 71 If a class or struct implements an interface that contains hidden members, then some members must necessarily be implemented through explicit interface member implementations. [Example: For example
interface IBase  
{  
   int P { get; }  
}  
interface IDerived: IBase  
{  
   new int P();  
}  
An implementation of this interface would require at least one explicit interface member implementation, and would take one of the following forms
class C: IDerived  
{  
   int IBase.P { get {...} }  
   int IDerived.P() {...}  
}  
class C: IDerived  
{  
   public int P { get {...} }  
   int IDerived.P() {...}  
}  
class C: IDerived  
{  
   int IBase.P { get {...} }  
   public int P() {...}  
}  
end example]
Paragraph 81 When a class implements multiple interfaces that have the same base interface, there can be only one implementation of the base interface. [Example: In the example
interface IControl  
{  
   void Paint();  
}  
interface ITextBox: IControl  
{  
   void SetText(string text);  
}  
interface IListBox: IControl  
{  
   void SetItems(string[] items);  
}  
class ComboBox: IControl, ITextBox, IListBox  
{  
   void IControl.Paint() {...}  
   void ITextBox.SetText(string text) {...}  
   void IListBox.SetItems(string[] items) {...}  
}  
it is not possible to have separate implementations for the IControl named in the base class list, the IControl inherited by ITextBox, and the IControl inherited by IListBox. Indeed, there is no notion of a separate identity for these interfaces. Rather, the implementations of ITextBox and IListBox share the same implementation of IControl, and ComboBox is simply considered to implement three interfaces, IControl, ITextBox, and IListBox. end example]
Paragraph 91 The members of a base class participate in interface mapping. [Example: In the example
interface Interface1  
{  
   void F();  
}  
class Class1  
{  
   public void F() {}  
   public void G() {}  
}  
class Class2: Class1, Interface1  
{  
   new public void G() {}  
}  
the method F in Class1 is used in Class2's implementation of Interface1. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS