Archived

This forum has been archived. Please start a new discussion on GitHub.

difference between proxies from class and from interface

Hi,

Is possible something like:
class C {
  string str;
  nonmutating string getString();
};

interface I extends C {
};

class D implements C {
};

Can I create interface by extending "interface from class" C? and the same - if I can create class D implementing only "interface from class" C?

I know that in normal languages it is not possible, but there, how I see ICE works, if I pass class by reference it is the same like I pass "interface from class"... and because it is only interface, I would like to implement more these interfaces in one.

Comments

  • marc
    marc Florida
    A class can implement multiple interfaces and in addition extend a single class. An interface can extend multiple other interfaces, but not classes. No other inheritance relationships are possible. Slice follows the Java rules in this respect. If Slice were to support more inheritance relationships, such as multiple class inheritance, a language mapping from Slice to Java would not be possible, or at least very complicated.
  • Thank you,
    marc wrote:
    If Slice were to support more inheritance relationships, such as multiple class inheritance, a language mapping from Slice to Java would not be possible, or at least very complicated.

    but I would not like to use multiple class inheritace...

    My qouestion was there because I thougth that
    class C {
      string a;
      nonmutating string getA();
    };
    

    is somehow implemented like:
    interface C {
      nonmutating string getA();
    };
    
    class C implements C {
      string a;
    };
    

    and when C is used for passing by reference, it is that interface, if it is passed by value, it is that class.

    And I would like to implement only more these interfaces (thats why I used word "implements" and not "extends").

    On other hand if it is not possible, it is OK.

    thank you,
    Michal
  • kovacm wrote:
    Is possible something like:
    class C {
      string str;
      nonmutating string getString();
    };
    
    interface I extends C {
    };
    
    class D implements C {
    };
    

    Can I create interface by extending "interface from class" C? and the same - if I can create class D implementing only "interface from class" C?

    There is no specific mechanism for inheriting "just the interface part" of a class, and it is illegal for an interface to derive from a class. But you can rearrange the Slice as follows to get the same effect:
    interface COps {
      nonmutating string getString();
    };
    
    class C implements COps {
      string str;
    };
    
    interface I extends COps {
    };
    
    class D implements COps {
    };
    

    Cheers,

    Michi.