Friday, April 21, 2006

Explicit Interface Implementation

Boo, like C# has "explicit interface implementation."

It is possible for two interfaces to have the same name. If interfaces were by default visible then there could be confusion as to which member of which interface was being called.

You therefore need to cast your variables explicitly to the interface that you are calling. An example from http://msdn2.microsoft.com/en-us/library/ms173157(VS.80).aspx is as follows:

SampleClass obj = new SampleClass();
//obj.Paint(); // Compiler error.

IControl c = (IControl)obj;
c.Paint(); // Calls IControl.Paint on SampleClass.

ISurface s = (ISurface)obj;
s.Paint(); // Calls ISurface.Paint on SampleClass.

0 Comments:

Post a Comment

<< Home