[Mono-osx] MacOS bindings and MonoDevelop.

Miguel de Icaza miguel at novell.com
Tue May 19 12:58:31 EDT 2009


Hello Eugeny,

> Do you mean overrides for imported to .NET runtime Objective-C classes
> or exported to Objective-C .NET classes? For exported classes
> programmer should know such fundamental things of Objective-C like
> that all methods are virtual (like in Java). He can write following to
> 'override' exported Objective-C methods:
> class Foo : Control {
>  public new bool Enable {
>  get { ... };
>  set { ... };
>  }
> }
> 
> 'virtual' specifier makes sense only for C# code that uses such
> methods, but makes no sense while exporting. Also I can write
> additional code that will throw exception forALL 'virtual' methods
> that user want to export to prevent such misunderstanding.

The problem with using `new' instead of `virtual' to override methods is
that your code is not polymorphic.   For example:

	public DerivedUIButton : UIButton {
	    // If using `new' instead of `virtual' as suggested by
	    // Eugeny:
	    public new bool Enable { 
		set { 
		    Foo (); 
		    base.Enable=value
		}
	    }
	}
	UIButton GetButton ()
	{
		if (foo)
			return a UIbutton ();
		else
			return a DerivedUIButton ();
	}

Then the code:

	GetButton ().Enable = false;

Would always call UIButton.Enable, it has no way of ever calling the
Enable method declared in DerivedUIButton, and "Foo" will never be
called.

Miguel.



More information about the Mono-osx mailing list