I don't need to test my programs. I have an error-correcting modem.

Interfaces

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

An Interface class is a special type of class that only defines function prototypes. Other classes implementing an interface must implement all functions defined by the interface class.

Interfaces that don't have any member declarations are called marker interfaces because they do nothing else but marking the implementing class. In Java this concept is used e.g. to specify whether list implementations support fast access in random order. In UnrealScript, empty interfaces are not always just marker interfaces. The otherwise empty interface classes in UT3 and UDK are all declared as "native" and thus contain logic or definitions declared in native C++ code.


Syntax[edit]

Interface classes start with an interface declaration:

interface InterfaceName [extends ParentInterface] [modifiers];

The extends clause is optional for interface classes. If omitted, the interface extends class Interface. The Interface class itself conceptually extends class Object, but should actually be seen as independent from the class tree. A within clause is not allowed for interface declarations.

Interface modifiers[edit]

Only two modifiers can be found in UT3 and UDK interface declarations:

dependson
The interface should be compiled after the specified classes or interfaces. This can be used to ensure struct and enum types used as parameter or return types in function declarations are already known to the compiler. It is only necessary if the class or interface is in the same package as this interface.
native
The interface contains additional logic or definitions in native C++ code.

Interface members[edit]

Interfaces can declare functions, structs and enums. The functions they declare should not have a body because they cannot be called anyway. Variable declarations are not allowed in interfaces and would not make any sense, if you think about it.

Usage[edit]

Interfaces can be implemented in any class by including the modifier implements(InterfaceName) in the class declaration. The compiler will make sure the class correctly implements all functions specified by the interface. Instances of that class or any of its subclasses can be assigned to variables of type InterfaceName. Functions defined in the interface can be called on any object assigned to such a variable.