What's New: AL - Interfaces (2024 release wave 2)
AL interface extension in the 2024 release wave 2: how to extend an existing interface without breaking existing implementations, and how to use the new is and as operators for type checking and casting. Shown with a shipping cost calculator sample app using a provider model.
- Introduction and Sample App Overview
- Shipping Cost Calculator UI and Architecture
- Interface, Enum and Orchestrator Code Structure
- Provider Implementation and Architecture Diagram
- Limitations of the Current Interface Model
- Interface Extension Feature - Syntax and Benefits
- Implementing Extended Interfaces in Code
- Type Checking and Casting with Is and As Operators
- Live Demo of Extended Interfaces
- Conclusion and Summary
Overview
The video builds on a shipping cost calculator sample app made of an interface, an enum, an orchestrator codeunit and provider codeunits. It uses the app to show the limit of the current interface model: adding a method to an interface breaks every existing provider app that implements it.
Key points
- Interfaces were first released in AL more than four years before this video, integrated with enums for extensibility.
- Adding a new method to an existing interface breaks all existing provider apps that implement it.
- Interface extension creates a new interface that extends an existing one; the syntax is the normal interface declaration plus the extends keyword.
- Implementors must implement all methods from all extended interfaces. Existing enums are not changed, so old implementations keep working.
- The is operator is a Boolean expression that tests whether an interface instance also implements another interface. Its left side must be an interface instance or a variant.
- The as operator casts an interface instance to another interface type and errors if the cast is not possible, so check with is first.
- A new common base interface, unknown interface, was added to the system application for generic checks on whether an unknown interface implements a specific interface.
Features
| Feature | Status | At |
|---|---|---|
| Interface Extension | status not stated, demoed | 7:36 |
| Type Checking with Is Operator for Interfaces | status not stated, demoed | 10:02 |
| Interface Casting with As Operator | status not stated, demoed | 10:59 |
| Unknown Interface Type | status not stated | 11:32 |
AL objects mentioned
As heard in the captions. A name that matches one object page by exact type and name links to it; the others stay as named.
- interface “I shipping provider” at 2:26
- enum “shipping vendor” at 3:06
- codeunit “shipping cost orchestrator” at 3:27
- codeunit “standard shipping provider” at 4:27
- interface “I express shipping provider” at 7:56
- interface “I unknown interface” at 11:48
Not found in BC28-30: interface “I shipping provider”, enum “shipping vendor”, codeunit “shipping cost orchestrator”, codeunit “standard shipping provider”, interface “I express shipping provider”, interface “I unknown interface”.
Quotes
- 0:20 “it is more than four years since we first released interfaces in Al and although it was integrated with voms from for extensibility from”
- 6:18 “what we would like to do is add a new myth to the interface but that breaks all the existing provider apps because they”
- 7:36 “all we want is just to extend the existing interface without changing or breaking everything so what we have now introduced is a way”
- 8:16 “this is one of the new features extending interfaces syntax is you have the normal interface declaration and then you add extend and then”
- 10:38 “if provider is express shipping provider it’s a it’s a Boolean expression that tests if the provider also implements I express shipping provider”
- 11:48 “we have added a i an unknown interface that you can use that gives a common ground for anyone who wants this kind of”
- 12:54 “cannot be cast to the right side you will get an error and this is why you should in most cases check first”
Presenters (as heard): Esp new Christopherson.
