Introduction

Completed

In application language (AL), you would use an interface when you want to decide which capabilities need to be available for an object while allowing actual implementations to differ, provided that they follow the defined interface.

This process allows you to write code that reduces the dependency on implementation details, helps simplify the reuse of code, and supports a polymorphic way of calling object methods, which can be used for substituting business logic.

You can use the new interface object to declare an interface name along with its methods and apply the implement's keyword along with the interface names on objects that implement the interface methods. The interface object doesn't contain code, only signatures, and it can't be called from code but must be implemented by other objects.

The compiler checks to ensure that implementations adhere to assigned interfaces. The QuickFix CodeAction can be used to insert interface stubs if the compiler errors on one or more interface implementations are missing.

You can declare variables as a given interface to allow the passing of objects that implement the interface and then call interface implementations on the passed object in a polymorphic manner.

An interface in AL is a syntactical contract that can be implemented by a non-abstract method.

You can use the interface to:

  • Define which capabilities must be available for an object.

  • Allow actual implementations to differ.

  • Comply with the defined interface.

This will allow you to write code that:

  • Reduces the dependency on implementation details

  • Helps make code reuse easier.

  • Supports a polymorphic way of calling object methods that can be used for substituting business logic.

The interface declares an interface name along with its methods and codeunits that implement the interface methods. The interface must use the implements keyword along with the interface name(s).