Interfaces in AL (part 1)

With Microsoft Dynamics 365 Business Central 2020 Wave 1 (respectively with Runtime 5.0) a new object type has been introduced – Interfaces. This term is well known from other programming languages and probably a lot of readers have already used them in some way.

The general definition of the interface object could be found anywhere on the Internet. For example, the definition on Wikipedia:

The term interface is used to define an abstract type that contains no data but defines behaviours as method signatures. A class having code and data for all the methods corresponding to that interface and declaring so is said to implement that interface.

An interface is thus a type definition; anywhere an object can be exchanged (for example, in a function or method call) the type of the object to be exchanged can be defined in terms of one of its implemented interfaces or base-classes rather than specifying the specific class. This approach means that any class that implements that interface can be used.

Usually a method defined in an interface contains no code and thus cannot itself be called; it must be implemented by non-abstract code to be run when it is invoked.

https://en.wikipedia.org/wiki/Interface_(computing)

Okay, but what does it mean in term of programming in AL language? The interface described in the quotation above is the new special object type “Interface” and the “non-abstract class” is, in our case, Codeunit object with a special construction that defines that the Codeunites implements an Interface.

 interface "TKA Our Interface Object"
 {
    procedure MyProcedureDefinedInTheInterfaceObject();
 }

 codeunit 50001 "TKA Our Codeunit Object" implements "TKA Our Interface Object"
 {
    procedure MyProcedureDefinedInTheInterfaceObject();
    begin
        // TODO Implementation of procedure MyProcedureDefinedInTheInterfaceObject
    end;
 }

In the next part of this article series, I will describe Interfaces on the more advanced example.

2 thoughts on “Interfaces in AL (part 1)

  1. Pingback: Interfaces in AL (part 2) — Microsoft Dynamics 365 - Ing. Tomáš Kapitán

  2. Pingback: Interfaces in AL (part 3) — Microsoft Dynamics 365 - Ing. Tomáš Kapitán

Leave a Reply

Your email address will not be published. Required fields are marked *