13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATIONclass TextBox: Control{public override void Paint() {…}}the following effects will now be observedControl c = new Control();TextBox t = new TextBox();IControl ic = c;IControl it = t;c.Paint(); // invokes Control.Paint();t.Paint(); // invokes TextBox.Paint();ic.Paint(); // invokes Control.Paint();it.Paint(); // invokes TextBox.Paint();end example]Since explicit interface member implementations cannot be declared virtual, it is not possible to override anexplicit interface member implementation. However, it is perfectly valid for an explicit interface memberimplementation to call another method, and that other method can be declared virtual to allow derived classes tooverride it. [Example: For exampleinterface IControl{void Paint();}class Control: IControl{void IControl.Paint() { PaintControl(); }protected virtual void PaintControl() {…}}class TextBox: Control{protected override void PaintControl() {…}}Here, classes derived from Control can specialize the implementation of IControl.Paint by overriding thePaintControl method. end example]20.4.4 Interface re-implementationA class that inherits an interface implementation is permitted to re-implement the interface by including it in thebase class list.A re-implementation of an interface follows exactly the same interface mapping rules as an initialimplementation of an interface. Thus, the inherited interface mapping has no effect whatsoever on the interfacemapping established for the re-implementation of the interface. [Example: For example, in the declarationsinterface IControl{void Paint();}class Control: IControl{void IControl.Paint() {…}}class MyControl: Control, IControl{public void Paint() {}}the fact that Control maps IControl.Paint onto Control.IControl.Paint doesn’t affect the reimplementationin MyControl, which maps IControl.Paint onto MyControl.Paint. end example]290

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!