{"title":"Interfaces in AL","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-interfaces-in-al/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-interfaces-in-al, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-interfaces-in-al","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn about interfaces in AL, including default method implementations and the RequiredPending attribute for evolving interfaces safely.","date":"2026-08-25","meta":{"topic":"article"},"outline":[{"level":2,"title":"Extending interfaces","slug":"extending-interfaces","at":1756,"chars":233},{"level":2,"title":"Default interface methods","slug":"default-interface-methods","at":1989,"chars":2189},{"level":3,"title":"Syntax","slug":"syntax","at":2785,"chars":297},{"level":3,"title":"Runtime identity","slug":"runtime-identity","at":3082,"chars":262},{"level":3,"title":"Transitioning default methods to required","slug":"transitioning-default-methods-to-required","at":3344,"chars":834},{"level":2,"title":"Interface creation","slug":"interface-creation","at":4178,"chars":459},{"level":2,"title":"Some design guidelines","slug":"some-design-guidelines","at":4637,"chars":1124},{"level":2,"title":"Snippet support","slug":"snippet-support","at":5761,"chars":203},{"level":2,"title":"Interface example","slug":"interface-example","at":5964,"chars":2728},{"level":2,"title":"Create List and Dictionary of an interface","slug":"create-list-and-dictionary-of-an-interface","at":8692,"chars":2384},{"level":2,"title":"Default interface method implementations","slug":"default-interface-method-implementations","at":11076,"chars":2386},{"level":3,"title":"Syntax","slug":"syntax-1","at":11696,"chars":384},{"level":3,"title":"Implementing an interface with default methods","slug":"implementing-an-interface-with-default-methods","at":12080,"chars":768},{"level":3,"title":"Dispatch behavior","slug":"dispatch-behavior","at":12848,"chars":614},{"level":2,"title":"The RequiredPending attribute","slug":"the-requiredpending-attribute","at":13462,"chars":1462},{"level":3,"title":"Syntax","slug":"syntax-2","at":13866,"chars":474},{"level":3,"title":"Lifecycle for evolving interfaces","slug":"lifecycle-for-evolving-interfaces","at":14340,"chars":584},{"level":2,"title":"Related information","slug":"related-information","at":14924,"chars":341}],"text":"> INTRODUCED IN: Business Central 2020 release wave 1\nAn 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.\nThis allows for writing code that reduces the dependency on implementation details, makes it easier to reuse code, and supports a polymorphic way of calling object methods, which again can be used for substituting business logic.\nThe 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.\nThe AL compiler checks to ensure that implementations adhere to assigned interfaces.\nYou can declare variables as a given interface to allow passing objects that implement the interface, and then call interface implementations on the passed object in a polymorphic manner.\n> NOTE\n> With Business Central 2023 release wave 1, you can use the Go to Implementations option in the Visual Studio Code context menu (or press Ctrl+F12) on an interface to view all the implementations within scope for that interface. This is supported on interfaces, and on codeunits and enums, which implement an interface, as well as on their procedures if they map to a procedure on an interface. It's also supported on codeunit variables of type interface to jump to other implementations of that specific interface.\n## Extending interfaces\n> APPLIES TO: Business Central 2024 release wave 2 and later.\nInterfaces in AL can be extended to allow other changes to interfaces without changing the core functionality. See devenv-interfaces-in-al-extend.\n## Default interface methods\n> APPLIES TO: Business Central 2026 release wave 2 and later.\nInterface methods can include a default implementation (a body). Methods with a body are optional - implementing codeunits don't have to override them. Methods without a body remain required and must be implemented by every codeunit that uses the interface.\nDefault interface methods let you add new functionality to a published interface without breaking existing implementors. Because the new method already has a body, existing codeunits continue to compile and use the default behavior until they choose to override it.\nWhen you use Go to Implementations on an overriding method in a codeunit, the results include the matching default interface method and explicit implementations in other codeunits.\n### Syntax\n```al\ninterface IMyInterface\n{\n    // Required method - all implementors must provide this\n    procedure RequiredMethod();\n\n    // Default method - implementors can override, but don't have to\n    procedure OptionalMethod(): Text\n    begin\n        exit('default value');\n    end;\n}\n```\n### Runtime identity\nThe interface runtime identifier is computed from the required (non-default) methods only. Adding a default method to a published interface doesn't change the runtime identifier, which means dependent extensions don't need to be recompiled.\n### Transitioning default methods to required\nWhen you decide that a default method must be implemented by all consumers, you can't simply remove the body in the next version. That change would break existing implementations. Instead, follow the two-phase transition using the attributes/devenv-requiredpending-attribute:\n1. Phase 1: Add `[RequiredPending]` to the default method. Implementors receive a compiler warning (AL0924) encouraging them to add their own implementation.\n2. Phase 2: In a later major version, remove the body and the `[RequiredPending]` attribute to make the method required. The AppSourceCop rule analyzers/appsourcecop-as0149 warns about the runtime ID change.\nSkipping Phase 1 and directly removing the body triggers analyzers/appsourcecop-as0148, which is an error.\nSee devenv-interface-method-lifecycle.\n## Interface creation\nWhen creating interfaces, consider the following guidelines:\n Use meaningful names for interfaces that clearly convey their purpose.\n Keep interfaces focused and cohesive, with a few related methods.\n Use versioning for interfaces to manage changes over time.\n Document the expected behavior of each method in the interface.\n Consider using #default-interface-method-implementations for methods in interfaces to reduce boilerplate code.\n## Some design guidelines\n Avoid adding required methods to published interfaces. Analyzer rule analyzers/appsourcecop-as0066 catches this condition.\n Use default methods to add new functionality to published interfaces safely.\n Use `[RequiredPending]` when a default method must eventually become required. See attributes/devenv-requiredpending-attribute.\n Design interfaces with extension in mind. See devenv-interfaces-in-al-extend.\n Understand circular reference limitations. Analyzer rule AL0852<diagnostics/diagnostic-al852> catches this.\n Interfaces can only contain procedure declarations. The analyzer rules AL0584<diagnostics/diagnostic-al584>, AL0585<diagnostics/diagnostic-al585>, and AL0612<diagnostics/diagnostic-al612> catch this.\n Avoid naming conflicts with built-in procedures. Analyzer rule AL0616<diagnostics/diagnostic-al616> catches this.\n When implementing multiple interfaces avoid duplication. The analyzer rules AL0587<diagnostics/diagnostic-al587> and AL0675<diagnostics/diagnostic-al675> catch this.\n Learn more about the full lifecycle of interface methods in devenv-interface-method-lifecycle.\n## Snippet support\nTyping the shortcut tinterface creates the basic layout for an interface object when using the AL Language extension for Microsoft Dynamics 365 Business Central in Visual Studio Code.\n## Interface example\nThe following example defines an interface IAddressProvider, which has one method getAddress with a certain signature. The codeunits CompanyAddressProvider and PrivateAddressProvider both implement the IAddressProvider interface, and each define a different implementation of the getAddress method; in this case a simple variation of address value.\nThe MyAddressPage is a simple page with an action that captures the choice of address and calls, based on that choice, an implementation of the IAddressProvider interface.\n```al\nnamespace MyCompany.AddressManagement;\n\ninterface \"IAddressProvider\"\n{\n    procedure GetAddress(): Text\n}\n\ncodeunit 50200 CompanyAddressProvider implements IAddressProvider\n{\n\n    procedure GetAddress(): Text\n    var\n        ExampleAddressLbl: Label 'Company address \\ Denmark 2800';\n\n    begin\n        exit(ExampleAddressLbl);\n    end;\n}\n\ncodeunit 50201 PrivateAddressProvider implements IAddressProvider\n{\n\n    procedure GetAddress(): Text\n    var\n        ExampleAddressLbl: Label 'My Home address \\ Denmark 2800';\n\n    begin\n        exit(ExampleAddressLbl);\n    end;\n}\n\nenum 50200 SendTo implements IAddressProvider\n{\n    Extensible = true;\n\n    value(0; Company)\n    {\n        Implementation = IAddressProvider = CompanyAddressProvider;\n    }\n\n    value(1; Private)\n    {\n        Implementation = IAddressProvider = PrivateAddressProvider;\n    }\n}\n\npage 50200 MyAddressPage\n{\n    PageType = Card;\n    ApplicationArea = All;\n    UsageCategory = Administration;\n\n    layout\n    {\n        area(Content)\n        {\n            group(MyGroup)\n            {\n            }\n        }\n    }\n\n    actions\n    {\n        area(Processing)\n        {\n            action(GetAddress)\n            {\n                ApplicationArea = All;\n\n                trigger OnAction()\n                var\n                    AddressProvider: Interface IAddressProvider;\n                begin\n                    AddressproviderFactory(AddressProvider);\n                    Message(AddressProvider.GetAddress());\n                end;\n            }\n\n            action(SendToHome)\n            {\n                ApplicationArea = All;\n\n                trigger OnAction()\n                begin\n                    sendTo := sendTo::Private;\n                end;\n            }\n\n            action(SendToWork)\n            {\n                ApplicationArea = All;\n\n                trigger OnAction()\n                begin\n                    sendTo := sendTo::Company;\n                end;\n            }\n        }\n    }\n\n    local procedure AddressproviderFactory(var iAddressProvider: Interface IAddressProvider)\n    begin\n        iAddressProvider := sendTo;\n    end;\n\n    var\n        sendTo: enum SendTo;\n}\n```\n## Create List and Dictionary of an interface\n> APPLIES TO: Business Central 2025 release wave 1 (v26) and later.\nThe methods-auto/dictionary/dictionary-data-type and methods-auto/list/list-data-type data types offer efficient lookup of key-value pairs and ordered collections, and allow managing collections of data dynamically. From runtime 15.0, you can create lists or dictionaries of interfaces.\nThe following example illustrates how to create a methods-auto/dictionary/dictionary-data-type of interfaces:\n```al\nnamespace MyCompany.BarcodeExamples;\n\nusing System.Text;\n\ncodeunit 50120 MyDictionaryCodeunit\n{\n    procedure MyProcedure(): Dictionary of [Integer, Interface \"Barcode Font Provider\"]\n    var\n        localDict: Dictionary of [Integer, Interface \"Barcode Font Provider\"];\n        IProvider: Interface \"Barcode Font Provider\";\n    begin\n        localDict.Add(2, IProvider);\n        exit(localDict);\n    end;\n}\n```\nThe following example illustrates how to create a methods-auto/list/list-data-type of interfaces:\n```al\nnamespace MyCompany.ShapeExamples;\n\ninterface IShape\n{\n    procedure GetArea(): Decimal;\n}\n\ncodeunit 50101 Circle implements IShape\n{\n    procedure GetArea(): Decimal\n    var\n        Radius: Decimal;\n    begin\n        Radius := 5; // Example radius\n        exit(3.14 * Radius * Radius); // Area of a circle: πr²\n    end;\n}\n\ncodeunit 50102 Square implements IShape\n{\n    procedure GetArea(): Decimal\n    var\n        SideLength: Decimal;\n    begin\n        SideLength := 4; // Example side length\n        exit(SideLength * SideLength); // Area of a square: side²\n    end;\n}\n\ncodeunit 50103 ShapeListDemo\n{\n    trigger OnRun()\n    var\n        ShapeList: List of [Interface IShape];\n        Shape: Interface IShape;\n        CircleShape: Codeunit Circle;\n        SquareShape: Codeunit Square;\n    begin\n        // Add instances of Circle and Square to the list\n        ShapeList.Add(CircleShape);\n        ShapeList.Add(SquareShape);\n\n        // Iterate through the list and display the area of each shape\n\n        foreach Shape in ShapeList do begin\n            Message('The area of the shape is: %1', Shape.GetArea());\n        end;\n    end;\n}\n```\nIn the System Application, you can find the complete examples of using a list of interfaces in the Telemetry Logger<https://github.com/search?q=repo%3Amicrosoft%2FBCApps+%22List+of+%5BInterface%22&type=code>.\n## Default interface method implementations\n> APPLIES TO: Business Central 2026 release wave 2 and later, runtime version 18.0+\nInterfaces can include method bodies that serve as default implementations. Codeunits that implement the interface can omit these methods to inherit the default behavior, or provide their own implementation to override it.\nDefault methods let you evolve interfaces over time without breaking existing implementors. When you add a new method with a default body, all codeunits that already implement the interface continue to compile and run - they inherit the default behavior automatically.\n### Syntax\nDefine a default method by adding a body to a method declaration inside the interface object:\n```al\ninterface IPaymentMethod\n{\n    // Default implementation — implementors can omit or override\n    procedure GetTransactionFee(): Decimal\n    begin\n        exit(0);\n    end;\n\n    // Abstract — must be implemented\n    procedure ValidateAmount(Amount: Decimal): Boolean;\n}\n```\n### Implementing an interface with default methods\nWhen a codeunit implements an interface that has default methods, the codeunit can choose to:\n Inherit the default by not declaring the method at all.\n Override the default by declaring its own implementation.\n```al\ncodeunit 50100 CashPayment implements IPaymentMethod\n{\n    // GetTransactionFee is inherited from the interface default\n\n    procedure ValidateAmount(Amount: Decimal): Boolean\n    begin\n        exit(Amount > 0);\n    end;\n}\n\ncodeunit 50101 CreditCardPayment implements IPaymentMethod\n{\n    // Override the default\n    procedure GetTransactionFee(): Decimal\n    begin\n        exit(2.5);\n    end;\n\n    procedure ValidateAmount(Amount: Decimal): Boolean\n    begin\n        exit(Amount > 0);\n    end;\n}\n```\n### Dispatch behavior\nDefault methods are dispatched through the interface variable, not through the implementing codeunit's public API. This means you must call the method on an Interface variable:\n```al\nprocedure ShowFee()\nvar\n    PaymentMethod: Interface IPaymentMethod;\n    Cash: Codeunit CashPayment;\nbegin\n    PaymentMethod := Cash;\n    Message('Fee: %1', PaymentMethod.GetTransactionFee()); // Returns 0 (default)\nend;\n```\nCalling `GetTransactionFee()` directly on a `Codeunit CashPayment` variable won't work if the codeunit doesn't declare the method - use an `Interface IPaymentMethod` variable instead.\n## The RequiredPending attribute\nThe `[RequiredPending]` attribute marks a default interface method as becoming required (abstract) in a future version. This attribute gives implementors advance notice to add their own implementation before the default body is removed.\nWhen applied, the compiler reports a warning for any codeunit that relies on the default implementation instead of providing its own.\n### Syntax\n```al\ninterface IPaymentMethod\n{\n    [RequiredPending('Will become mandatory in v28.0', '28.0')]\n    procedure GetTransactionFee(): Decimal\n    begin\n        exit(0);\n    end;\n}\n```\nThe attribute takes two parameters:\n Message - A description shown in the compiler warning, explaining why and when the method becomes required.\n Version - The version in which the method becomes required. This parameter is informational and doesn't trigger automatic enforcement.\n### Lifecycle for evolving interfaces\nThe `[RequiredPending]` attribute supports a safe transition lifecycle for published interfaces:\n1. Add method with default body - Existing implementers continue to work without changes.\n2. Mark as `[RequiredPending]` - Implementers receive a compiler warning prompting them to add their own implementation.\n3. Remove the default body - The method becomes abstract (required). Implementers that didn't update now get a compiler error.\nThe AppSourceCop rules analyzers/appsourcecop-as0148 and analyzers/appsourcecop-as0149 enforce this lifecycle.\n## Related information\ndevenv-codeunit-object\ndevenv-extensible-enums\ndevenv-interfaces-in-al-extend\nType testing and casting operators for interfaces<devenv-interfaces-in-al-operators>\ndevenv-interface-method-lifecycle\nattributes/devenv-requiredpending-attribute\nmethods-auto/dictionary/dictionary-data-type\nmethods-auto/list/list-data-type"}