[IronPython] IronPython and polymorphism? Help with interfaces

Dino Viehland dinov at exchange.microsoft.com
Wed Jan 23 21:35:41 CET 2008


I agree, we should document it, unfortunately our documentation is still woefully inadequate  :(.  Maybe someone could add it to the IronPython cookbook page in the mean time? (http://www.ironpython.info/index.php/Main_Page).

But as for it "working in C#"...  Consider the code:

using System;

public class Foo : ICloneable {
    public object Bar() {
        return  Clone();
    }

    object ICloneable.Clone() {
        return null;
    }
}

That code doesn't compile because you must be explicit to access the Icloneable method.  This compiles:

using System;

public class Foo : ICloneable {
    public object Bar() {
        return  ((ICloneable)this).Clone();
    }

    object ICloneable.Clone() {
        return null;
    }
}

As does:

using System;

public class Foo : ICloneable {
    public object Bar() {
        ICloneable x = this;
        return  x.Clone();
    }

    object ICloneable.Clone() {
        return null;
    }
}

But you must explicitly refer to the type somewhere.  Unfortunately we don't have type information at compile time so the only way to refer to the type is at runtime by getting the method from the interface.  But in either case both languages are requiring you to be explicit about your choice of method.    So conceptually I think we're fairly similar.


From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Miha Valencic
Sent: Wednesday, January 23, 2008 12:28 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython and polymorphism? Help with interfaces

Thanks for the explanation. The docs could/should mention that... :) I guess we're not used, because it works in C#, so it should double-work in Ipy. You know, inferred types and all... :))

rgds,
 Miha.
On Jan 23, 2008 9:21 PM, Dino Viehland <dinov at exchange.microsoft.com<mailto:dinov at exchange.microsoft.com>> wrote:

It's a feature, explicit interfaces require an explicit call  :) .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080123/aebbdae7/attachment.html>


More information about the Ironpython-users mailing list