Business Central 2026 release wave 2 (BC29): Evolve AL interfaces with default implementations (Default interface method implementations)

Dynamics 365 Business Central

Hi, Readers.
Dynamics 365 Business Central 2026 wave 2 (BC29) is generally available. More details: General Availability: Dynamics 365 Business Central 2026 release wave 2 (BC29).
I will continue to test and share some new features that I hope will be helpful. In this post, I would like to talk about Evolve AL interfaces with default implementations (Default interface method implementations).
Evolve AL interfaces with default implementations:

Add default method bodies to AL interfaces so existing implementors continue working, then use RequiredPending and analyzer rules to introduce required methods safely.

Business value: Extension publishers can add behavior to an interface without immediately requiring every implementing extension to change. Default methods provide a compatible implementation, while the new transition attribute and AppSourceCop rules support a managed path toward making a method mandatory in a future version. This reduces disruptive interface upgrades and gives dependent developers time to adopt new contracts.

https://www.microsoft.com/en-us/microsoft-365/roadmap?id=573352

Default interface method implementations:

Interfaces can now include method bodies that serve as default implementations. Codeunits implementing the interface can omit these methods to inherit the default behavior, or provide their own implementation to override it. This feature requires runtime version 18.0 or later.

An interface in AL is similar to an interface in any other programming language; it’s a syntactical contract that can be implemented by a nonabstract method. The interface is used to define which capabilities must be available for an object, while allowing actual implementations to differ, as long as they comply with the defined interface. More details: Interfaces in AL
This was a new object type in Business Central 2020 Wave1 (BC16).

The interface declares an interface name along with its methods, and codeunits that implement the interface methods, must use the implements keyword along with one or more interface names. The interface itself doesn’t contain any code, only signatures, and can’t itself be called from code, but must be implemented by other objects. Let’s look at a simple example.

1. Create a new interface object: Procedure with declaration only

2. Create a codeunit that implements this interface: declare the code of the procedure

The name and number of the procedure, whether it has a return value, and the type of the return value must be the same as defined in the interface object. Otherwise an error message will be displayed.

‘ImplementZYTest’ does not implement the interface member ‘ZYTestInterface.ShowMessage’. AL AL0582

And

‘PrivateAddressProvider’ does not implement the interface member ‘IAddressProvider.GetAddress2’. AL AL0582

3. Use the new Interface object:

Please note that if you do not specify which codeunit to read before calling the interface, the following error will be prompted.

Interface not initialized

There are two more special initialization ways:
1. Pass codeunit directly as a variable to the function

2. By Enum object: This is useful for situations where there are multiple procedures

Test code:

interface ZYTestInterface
{
    procedure ShowMessage()
}

codeunit 50102 ImplementZYTest implements ZYTestInterface
{
    procedure ShowMessage()
    begin
        Message('Hello World');
    end;
}

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage()
    var
        ZYTestInterface: Interface ZYTestInterface;
        ImplementZYTest: Codeunit ImplementZYTest;
    begin
        ZYTestInterface := ImplementZYTest;
        ZYTestInterface.ShowMessage();
    end;
}

Let’s look at a more complex example. (I modified the Microsoft example a bit)
The first is the definition of interface and codeunit. This time there are two codeunits implemented to the same interface.

The same interface is executed in two different actions, but the initialization codeunit is different.

Great.

PS: Interface example from Microsoft Learn

In this major release, Microsoft introduced the following updates:

Interfaces can now include method bodies that serve as default implementations. Codeunits implementing the interface can omit these methods to inherit the default behavior, or provide their own implementation to override it. This feature requires runtime version 18.0 or later.

Default methods are dispatched through the interface variable, not inherited by the implementing codeunit’s public API. Calling GetTransactionFee() on a Codeunit CashPayment variable will fail — use an Interface IPaymentMethod variable instead.

The new [RequiredPending] attribute marks a default interface method as becoming required in a future version. When applied, the compiler reports:

New AppSourceCop rules support the transition lifecycle:

  • AS0148: Flags methods whose default body was removed (made required) without first being marked [RequiredPending].
  • AS0149: Warns when interface method changes alter the runtime identifier, which may break dependent extensions until recompiled.

Let’s take a look at a simple example. In BC29 (runtime: 18.0), we can define a default method within an Interface object.

PS: In BC28.5 (runtime: 17.0) and previous versions

Procedure ‘DefaultGetAddress’ cannot have a body. AL AL0413

When implementing an interface in a codeunit, if there’s a default method, you’ll see the notice below. You can either override it or ignore it and use the default method as is.

Interface ‘IAddressProvider’ provides a default implementation for method ‘DefaultGetAddress’. Override it to customize the behavior. AL AL0925

For example,

Great. Give it a try!!!😁
PS: What’s new in AL and Tools (2026 release wave 2)

What's new in AL and Tools (2026 release wave 2)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL