Interface Declaration

About

The declaration of an interface is a virtual class that defines the methods, inheritance and reference mode of the interface. This interface is the base for any implementation and also the base for the automatically generated reference class.

An interface class must be named in the scheme of "ClassnameInterface". The automatically defined reference class will then be named "ClassnameRef".

Declaration

The declaration of an interface is a C++ class declaration extended with multiple Maxon API attributes.

In this example the following attributes are used:

  • MAXON_INTERFACE_BASES: Defines the base interfaces this interface inherits from. In this case the base interface is maxon::ObjectInterface, which is the base interface of all interfaces.
  • MAXON_INTERFACE: Marks a class declaration as a virtual interface declaration, defines the reference type (see below) and the interface ID.
  • MAXON_METHOD: Declares a member function as virtual. A component can implement this function. For other types of functions see Interface Methods.
  • MAXON_DECLARATION: Declares a public object that gives access to a specific implementation of this interface. See Published Objects.

The Source Processor will analyse the interface and will create additional classes (like the reference class) automatically. This generated code is stored in automatically generated header files. These header files must be included in the original header file that contains the interface declaration. These automatically generated header files are named after the original header file. If the original file is named myclass.h, the header files are named myclass1.hxx and myclass2.hxx.

Inheritance

An interface can be based on one or many other interfaces. For details see Interface Inheritance.

Reference Type

The reference type of an interface defines how instances of the reference class behave. For details see Reference Types.

Single Implementation

To attribute MAXON_INTERFACE_SINGLE_IMPLEMENTATION is used to declare that only one implementation of this interface is accepted. In any other case multiple implementations of a given interface can exist.

A typical use-case would be a static interface that only defines static methods.

Further Reading