Archived

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

Classes versus Interfaces used for callbacks

Hi!

Regarding the callback demo, I have noticed that its Slice code declares two classes, but no interfaces. Checking with the documentation again, it seems that one of the reasons is is that interfaces "allow behaviour to be implemented only on the server side". This makes sense to me, but I wonder: Could the class which in this example is implemented on the server anyways, have been replaced by an interface, and retain a class declaration only for the callback object to be implemented on the client? Something like this:
// original
class CallbackReceiver
{
    void callback();
};

[COLOR=blue]class[/COLOR] Callback
{
    void initiateCallback(CallbackReceiver* proxy);
    void shutdown();
};
// alternative
class CallbackReceiver
{
    void callback();
};

[COLOR=blue]interface[/COLOR] Callback
{
    void initiateCallback(CallbackReceiver* proxy);
    void shutdown();
};

Thanks,
Catalin

Comments

  • marc
    marc Florida
    This is wrong in the demo, it should be plain interfaces in both cases. There is no need to use classes. We will fix this.
  • Thank you. It means then, that what made sense to me does not apply in this particular setting of callbacks. :D It kind of makes sense to me now why it does not apply, but I am not sure.

    I am thinking of one more thing:

    In the current example (with classes), I have commented out the following line from the server code:
    CallbackPrx self = CallbackPrx::uncheckedCast(adapter->createProxy(Ice::stringToIdentity("callback")));
    

    Still everything works just as well as when the line is compiled. What is this line's role? As far as I can see, the self variable is not used anywhere in the remainder of the server code.

    I am sure that you guys have a lot of things to do, but if this demo is a piece of cake for you, could someone please post some code here which implements callbacks with interfaces.

    Thanks,
    Catalin
  • marc
    marc Florida
    Sorry, that's another mistake in the demo :( The line is of course not needed.

    As for changing from classes to interfaces, nothing special is needed other than simply changing "class" to "interface" in Callback.ice.