[Mono-docs-list] Re: [Gtk-sharp-list] Documentation effort: Documenting Gtk#

Miguel de Icaza miguel@ximian.com
14 Feb 2003 11:58:31 -0500


> Okay, but in this case it's very confusing - a user should never call
> Entry.StartEditing() should they? I've never encountered it using
> 'normal' gtk+.

They do that through interface invocation.  We just happen to make this
a lot easier than in Gtk ;-)

> I'm not sure what that even means - IIRC a lot of those "virtual"
> declarations are along a similar theme, which is I think what confused
> me in the first place.

Basically, assume this:

interface IHello {
	void SayHello ();

class EnglishGreeter : IHello {
	public void SayHello ()
		print "Hello";

The compiler knows that the `SayHello' method in EnglishGreeter is an
implementation of the interface method IHello.SayHello (this is called
an implicit interface implementation).  Notice that implicit interface
implementations have to be public.

Now, interface methods always have to be virtual (that is how it
actually works inside the runtime), that is why the compiler flags the
method as virtual (even when it is not declared in that way in the
source code).

As a cultural note: just like there is implicit interface
implementation, .NET provides a mechanism called explicit interface
implementation.  In this form, the compiler does not have to find the
best match, but the programmer explicitly has to flag the method, like

class EnglishGreeter : IHello {
	void IHello.SayHello () { ... }

Notice that the method is not public.  But it will still be virtual.