Next: , Previous: , Up: Creating an Interface   [Contents][Index]


3.2.2 Interface Examples

3.2.2.1 An interface with three events and a simple behaviour

The following interface has three events defined: two in events and one out event. The direction is as seen from the component implementing this interface.

interface IMotion
{
  in void start();
  in void stop();
  out void ready();
  behaviour
  {
    on start, stop: {}
  }
}

3.2.2.2 An interface specifying an interaction protocol

This example shows an interface with a more complex interaction protocol, where the start event is only allowed in case the interface is in state Off and the stop event is only allowed in case the interface is in state Active.

interface IMotion
{
  in void start();
  in void stop();
  out void started();
  out void ready();
  behaviour
  {
      enum State {Off, Active};
      State state = State.Off;
      [state.Off]
      {
          on start:
          {
              state = State.Active;
              started;
          }
          on stop: illegal;
      }
      [state.Active]
      {
          on start: illegal;
          on stop:
          {
              state = State.Off;
              ready;
          }
      }
  }
}

See also: