Home Help Center

difference between proxies from class and from interface

kovacmkovacm Member Michal KovacOrganization: Charles University in PragueProject: Ferda Data Mining ✭✭
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

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    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.
  • kovacmkovacm Member Michal KovacOrganization: Charles University in PragueProject: Ferda Data Mining ✭✭
    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
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    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.
Sign In or Register to comment.