Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO: Business Central 2024 release wave 2 and later.
An interface in AL is a syntactical contract that can be implemented by a nonabstract method. It defines the capabilities an object must have while allowing actual implementations to differ, as long as they comply with the defined interface. Learn more in Interfaces in AL.
With Business Central 2024 release wave 2, extensible interfaces in AL are supported. Extending interfaces lets you create flexible and adaptable extensions. You can add new functionality without altering the core system, which can save time and resources and reduce the risk of introducing errors into the existing codebase.
When you declare an interface, you can extend one or more existing interfaces. The new interface inherits all the methods from the interfaces it extends. When you implement an interface that extends other interfaces, the implementing class or object must provide implementations for all the methods defined in the extended interfaces as well as any methods defined in the new interface itself. This ensures that the implementor adheres to the contract specified by all the interfaces involved.
Syntax
In the example, TheImplementor
can be used as both IFoo
, IBar
, and IFooBar
. The syntax for extending an interface is as follows:
interface IFoo
{
procedure Foo();
}
interface IBar
{
procedure Bar();
}
interface IFooBar extends IFoo, IBar
{
procedure FooBar();
}
codeunit 10 TheImplementor implements IFooBar
{
// Must implement IFoo, IBar, IFooBar
}
Extensible interfaces and operators
Extensible interfaces in AL also support the use of the testing and casting operators is
and as
. The is
operator allows you to check if an object implements a specific interface, while the as
operator enables you to cast an object to a specific interface type. This functionality enhances the flexibility and robustness of your code because it allows dynamic type checking and casting. Learn more in Type testing and casting operators for interfaces.