No items found.

OOP101 in AX 2012 part 3: Polymorphism

Polymorphism comes from the Greek words polys for many and morphe for shape. Inclusion polymorphism gives us the ability to use created object from the derived class wherever we can use object from the base class. I prepared an simple job based on the configuration from the post OOP101 in Dynamics AX 2012 part 1.

static void InterfacePolymorphism(Args _args)

‍

{

   Car car123 = new Car();

   Bike bike123 = new Bike();

   void testFcn(Drivable _driv)

   {

       Car tmpCar;

       Bike tmpBike;

       _driv.moveBack();

       _driv.turnRight();

       if(_driv is Car)

       {

           tmpCar = _driv as Car;

           tmpCar.printHello();

       }

       if (_driv is Bike)

       {

           tmpBike = _driv as Bike;

           tmpBike.printHello();

       }

   }

   testFcn(bike123);

   testFcn(car123);

}

‍

Output:

class Bike implements Drivable

{

...

public void printHello()

{

   info("I am a bike");

}

}

class Car implements Drivable

{

...

public void printHello()

{

   info("I am a car");

}

}

In this job I created a local function that takes as an argument object which implements an interface Drivable. Inside this job I call common methods like moveBack and turnRight but also after performing downcasting to derived classes I can call method specific to them like in this case printHello. As keyword is used to explicitly perform downcasting, and is on the other hand performs a type checking. When performing upcasting we do not need to use as keyword; upcasting can be done implicitly. The same job could be created for the inheritance configuration from OOP101 in AX 2012 part 2. By the means of polymorphism we can detach ourselves from the implementation of a given object and program for the given interface which is a great power that can significantly increase the productivity, especially when working on the big projects.

Zobacz inne

Wsparcie i rozwój

Podwykonawstwo Dynamics 365 Finance and Operations dla integratorów i partnerów Microsoft

Czytaj artykuł
Text Link
Wsparcie i rozwój

Kiedy wzmocnić zespół Dynamics 365 Finance and Operations zewnętrznym konsultantem

Czytaj artykuł
Text Link
Wsparcie i rozwój

Skąd wziąć konsultanta Dynamics 365 Finance and Operations do projektu

Czytaj artykuł
Text Link
Wróć do wszystkich

Szukasz partnera Microsoft? Porozmawiajmy o Twoim projekcie

Pracuj z zespołem, który zrealizował wdrożenia i projekty dla dziesiątek firm. Umów rozmowę wstępną i sprawdź:

Jak Dynamics 365 dopasować do procesów Twojej firmy, a nie odwrotnie

Które obszary warto zautomatyzować, żeby odzyskać czas i obniżyć koszty

Jak wygląda wdrożenie z Anegis krok po kroku: od analizy po wsparcie po starcie

Wybierz termin spotkania
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.