Semantics of pass by value for interface

Hi,

I'm a bit confused with the semantics of pass by value for an interface.
For a class, the semantics of pass by value and pass by reference (proxy) is easily understandable.
For an interface (remote) that is not implemented by a class, what is the meaning of transmitting this interface by value.
All examples from the documentation use the pass by reference for an interface but it is not stated that the pass by value is forbidden.
Furthermore, the slice compiler doesn't reject such definitions.

Chauk-Mean.

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    It is always possible to derive a class from an interface, therefore transferring an interface must be allowed by Slice. Consider:

    interface MyOps implements MyObj
    {
    // My operations...
    };

    class MyObjImplOne implements MyObj
    {
    // State...
    };

    class MyObjImplTwo implements MyObj
    {
    // Different state...
    };

    In this case, you have two different implementations for MyObj, with different state. In such case you might want to do something like this:

    MyObj getMyObj();

    The server could send you either of the two, as long as you have a factory for both in your client.
  • Thanks for the reply.

    I was initially surprised by the interface that is able to implement something :-) !

    But what makes me understand the whole thing is that "an interface can always be implemented by a class".

    I suggest that the ICE documentation contains some additional information regarding this feature, something in the SCLICE class description like :
    "As a SLICE interface can be implemented by a SCLICE class, it is legal to pass a SLICE interface by value. A runtime exception may be thrown if the type doesn't actually support the pass by value semantics."

    Furthermore, in order to ease the understanding for CORBA programmers like me, I suggest to add the following clarification in the section comparing SLICE and CORBA IDL :
    "In CORBA, an interface is always passed by reference and a valuetype is always passed by value. A valuetype may be passed by reference through one of its supported interface.
    Conversely, SLICE interface and class can be passed by value and by reference (through the use of the proxy operator *)."

    Chauk-Mean.
Sign In or Register to comment.