No items found.

OOP101 in AX 2012 part 1: Interfaces

One of such an abstract types that can be used in Dynamics AX is an interface. Interface allows us to detach contract from the class implementation, such an abstraction is very useful tool. Interface basically says that “hey, we want this class to implement such a methods”. For example we could imagine that we would want to have a car that would have an ability to drive, we could for instance implement an interface Drivable:

interface Drivable

{

void moveForth()

{

}

void moveBack()

{

}

void turnRight()

{

}

void turnLeft()

{

}

}

Having such an interface we can implement it on Car (concrete class) making Car class obliged to provide an implementation for the methods specified by the interface Drivable:

class Car implements Drivable

{

str model;

void moveForth()

{

/* Implementation needed */

}

void moveBack()

{

/* Implementation needed */

}

void turnRight()

{

/* Implementation needed */

}

void turnLeft()

{

/* Implementation needed */

}

private void otherMethod()

{

/* some additional functionality */

}

}

UML diagram for this configuration looks as follows:

Interface in Dynamics AX

We can also provide multiple interfaces like for example in SysTestCase class:

class SysTestCase extends SysTestAssert

implements SysTestable, SysTestSuiteProvider, SysTestSuiteActor, SysTestableExceptionExpected, SysTestListenerInformationProvider, SysTestableFaultExpected

Three things that developer needs to remember implementing interfaces:

1. Class that implements interfaces needs to provide implementation for all the methods from all the interfaces.

Implements interfaces error

2. Access level defined by interface cannot be restricted by derived class.

Access level defined error

3. In other languages for example Java interfaces could contain constant declarations (eg. static methods), but in X++ we do not have such an ability.

constant declarations error

Interfaces describe relationship “has-a”, so when you design one it can be useful to ask yourself “does that class has a property of …” for example “does this Car has a property of being Drivable” if yes then it should implement interface Drivable, this is why most of the interfaces in standard Dynamics implementation like SysTestable and SysComparable have names ending on –able. Unfortunately there is one significant drawback to using interfaces, namely they are not as flexible as using inheritance for example. Once the interface is implemented making modifications becomes hard and any addition to the interfaces at this point needs additional development.

Zobacz inne

Jak wybrać firmę do audytu i optymalizacji Dynamics 365?

Czytaj artykuł
Text Link

Migracja z Dynamics AX do Dynamics 365: jak wybrać partnera, koszt i etapy (2026)

Czytaj artykuł
Text Link

Jak wybrać firmę do wdrożenia Dynamics 365: kryteria, koszt i etapy (2026)

Czytaj artykuł
Text Link
Wróć do wszystkich

Porozmawiajmy o Twoim projekcie

Napisz, z czym przychodzisz: wdrożenie, migracja, rozwój systemu albo pytanie, na które szukasz odpowiedzi. Wracamy z konkretną propozycją następnego kroku, nie z prezentacją handlową.

Dziękujemy za wiadomość!
Oops! Something went wrong while submitting the form.
Microsoft AI Builder
Microsoft Copilot Studio
No items found.
No items found.
No items found.