Business Central AL Interfaces
THE AL “INTERFACE” OBJECT
A new object type is available in Business Central 2020 Wave1: “interface” object
Since I have never talked about it, I speak of it now, I don’t report particular examples as there are already several published.
Below are some links to very well made examples, useful for understanding how to best use them. Enjoy the reading.
An interface is used when you want to decide which features should be available for an object, while allowing actual implementations to differ as long as they conform to the defined interface.
This allows you to write code that reduces dependence on implementation details, facilitates code reuse, and supports a polymorphic way of calling object methods, which can be used again to replace business logic.
Use the new interface object to declare an interface name with its methods and apply the implementation keyword along with the interface names on the objects that implement the interface methods.
The interface object does not contain any code, only signatures, and cannot be called from the code but must be implemented by other objects. The compiler verifies that implementations adhere to the assigned interfaces.
A new CodeAction QuickFix can be used to insert interface stubs, if compiler errors are missing on one or more interface implementations. Variables can be declared as a specific interface to allow objects that implement the interface to pass and then call interface implementations on the object passed in a polymorphic way.
“In Microsoft AL the interface is a new object type in which you could define that procedures should exist in objects that implement that interface.”
Typing the shortcut tinterface will create the basic layout for an interface object when using the AL Language extension in Visual Studio Code.
INTERFACE PAGE ON MICROSOFT DOCS
** You need runtime “5.0”
An interface objects contains only the declared procedure, the body does not exist.
Now, we need to declare the body of the procedure in a codeunit that implements this interface
…and now we can test the New Interface object
On ItemList page extension, we can recall the interface after declaration on VAR section.
F5 or install the APP
ANOTHER EXAMPLE (by Microsoft)
Example link here https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-interfaces-in-al
ANOTHER GREAT EXAMPLES HERE
Great example here by Tobias Fester
L'articolo Business Central AL Interfaces proviene da Roberto Stefanetti Blog - Microsoft Dynamics 365 Business Central Blog.