Archived

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

how to pass/receive value which I dont know at compilation time

I would like to have in slice deffinition some functions like:
interface sample {
  idempotent void setProperty(string propertyName);
  nonmutating dataType getProperty(string propertyName, dataType propertyValue);
};
, where I don't know at compilation time which dataType it will be (only that it is pass by value not by reference). (better - I know dataType at compillation time, but for me is better to have one interface for many servants, which will use the same implementation of some methods, than to make new slice deffinitions for all servants and than implement it many times - or am I wrong, is there other possibility how implement some function only once?)

But, I think, if i do it like that a dataType is clean class which other extends, it will not work, is it right?
class dataType {
};

Comments

  • mes
    mes California
    Hi,

    You can certainly define dataType as an empty class, and then derive other Slice classes from it that add data members.

    See section 4.11 in the Ice manual for more information.

    Take care,
    - Mark
  • Thank you!

    For me is interesting that it will work.

    So if I have this slice definition:
    class a{};
    class b extends a{
      int a;
    };
    interface sample {
      idempotent void setProperty(a propertyValue);
    }
    

    I can implement setProperty function for example like this:
    void setProperty(a propertyValue)
    {
      b val = (b)propertyValue;
      val.a++;
    }
    
    (interesting for me is that ICE will not lost information about real class, it is nice)

    thanks