X hits on this document

838 views

0 shares

0 downloads

0 comments

298 / 396

Chapter ‎18   Unsafe code

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.

The members of a base class participate in interface mapping. 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.

13.4.3 Interface implementation inheritance

A class inherits all interface implementations provided by its base classes.

Without explicitly re-implementing an interface, a derived class cannot in any way alter the interface mappings it inherits from its base classes. For example, in the declarations

interface IControl { void Paint(); }

class Control: IControl { public void Paint() {...} }

class TextBox: Control { new public void Paint() {...} }

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.285

Document info
Document views838
Page views838
Page last viewedSun Dec 04 17:36:40 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments