About
An interface can be based on one or many other interfaces. This way the interface inherits the methods defined in the parent interfaces. An implementation of such an interface can re-implement the methods of the parent interfaces. It is also possible to use existing implementations of the inherited interfaces when the component is registered.
Parent interfaces are defined with the MAXON_INTERFACE_BASES attribute. The default parent interface is maxon::ObjectInterface.
Declaration
This example declares an interfaces that is directly based on maxon::ObjectInterface and an interface based on the previous interface:
{
public:
};
{
public:
};
#include "interface_inheritance1.hxx"
MAXON_DECLARATION(AdvancedNumberRef, AdvancedNumber,
"net.maxonexample.advancednumber");
#include "interface_inheritance2.hxx"
Definition: interface_inheritance.h:33
MAXON_METHOD void Add(maxon::Int n)
MAXON_METHOD maxon::Bool IsEven() const
MAXON_INTERFACE(AdvancedNumberInterface, MAXON_REFERENCE_NORMAL, "net.maxonexample.interfaces.advancednumber_example")
[interfaces_inheritance_interface_a]
Definition: interface_inheritance.h:14
MAXON_METHOD void SetNumber(maxon::Int number)
MAXON_INTERFACE(NumberInterface, MAXON_REFERENCE_NORMAL, "net.maxonexample.interfaces.number")
MAXON_METHOD maxon::Int GetNumber() const
Definition: objectbase.h:696
const Py_UNICODE size_t n
Definition: unicodeobject.h:1184
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:213
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:206
#define MAXON_REFERENCE_NORMAL(FREEIMPL)
Definition: interfacebase.h:1184
#define MAXON_DECLARATION(T, Name, id,...)
Definition: module.h:945
#define MAXON_METHOD
Definition: interfacebase.h:1012
#define MAXON_INTERFACE_BASES(...)
Definition: objectbase.h:1049
Implementation
Within the functions of an implementation it is possible to access the inherited functions using super:
class AdvancedNumberImpl :
public maxon::Component<AdvancedNumberImpl, AdvancedNumberInterface>
{
public:
{
_even = false;
if (number % 2 == 0)
_even = true;
super.SetNumber(number);
}
{
return _even;
}
{
self.SetNumber(number);
}
private:
};
@ Add
Definition: Python-ast.h:24
Definition: objectbase.h:2641
@ NORMAL
Normal Tag morphing.
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2199
The result class can be used like this:
const AdvancedNumberRef number = AdvancedNumber();
number.SetNumber(100);
if (number.IsEven())
number.Add(1);
if (!number.IsEven())
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
Components
Additional components are typically implementations of the inherited interfaces and define the specific behaviour of the registered component. They can be added using the MAXON_COMPONENT() attribute or by implementing maxon::ComponentRoot::ConfigureClass().
Further Reading