Sunday, July 3, 2016

Method Modifiers in AX 2012

Method Modifiers in AX 2012

Source Link :

https://vermaax.wordpress.com/2014/07/15/method-modifiers-in-ax-2012/

Abstract:
The method is declared but not implemented in a parent class. The method must be overridden in subclasses.
If you try to create an object from a subclass where one or more of the abstract methods belonging to the parent class have not been overridden, you will get a compiler error.
If you write any code in the abstract methods of a class, the code will never be executed and the compiler will throw an error. If you want to give some information to the child classes about why it the abstract method was created, you need can perform it through macros and the compiler will not throw an error.
Classes can also be abstract. Sometimes a class represents an abstract concept, but it should not be instantiated: Only subclasses should be instantiated. Such base classes can be declared abstract.
For Example, JournalForm is an abstract classes and JournalFormTable is a derived class which extends JournalForm Class and the JournalFormTable class has implemented all the abstract methods of the JournalForm class. For suppose, if JournalFormTable class didn’t override all the abstract methods of JournalForm, JournalFormTable will also become an abstract and its child class will override the left over methods.
If you want to restrict a class to get instantiated only through child classes, you need to put abstract to the class declaration even though if the classes doesn’t have any abstract methods.
Client:
It ensures that the method will be executed at Client tier. It can only be used on static methods. If the method is not static, specify the location by using the class property RunOn.
Display:
Indicates that the method’s return value is to be displayed on a form or a report. The value cannot be altered in the form or report.
The return value is typically a calculated value, for example, a sum.
You should add a display method as a table method whenever possible. This enables you to use that same code with more than one form or report.
If you want users to change the value that appears in the control, use the edit method modifier instead of display method
Edit:
The edit method modifier is used to indicate that a method’s return value is to be displayed on a form, and users can edit that value. If you don’t want users to edit the value, use a display method. It is just same as display method. edit methods are called each time the form is redrawn. They should not contain complex and time-consuming calculations.
Final:
If final is used at method level, it indicates that the method cannot be overridden in any class that derives from its class.
If final is signature of class declaration, it stops the inheritance to that class. A final class can’t be extended any further. It is simply opposite to abstract modifier.
Public:
Methods that are declared as public are accessible anywhere the class is accessible and can be overridden by subclasses. Methods that have no access modifier are implicitly public.
Protected:
Methods that are declared as protected can only be called from methods in the class and in subclasses that extend the class where the method is declared. If you try to access the methods from any other classes, the compiler will throw an error.
Private:
Methods that are declared as private can be called only from methods in the class where the private method is declared. It is used when we need to provide tight security to the members of the class.
Server:
It ensures that the method will be executed at Server tier. It can only be used on static methods. If the method is not static, specify the location by using the class property RunOn.
Static:
Specifies that the method is a class method and does not operate on an object. To use static methods of a class, you don’t have to instantiate the class and create an object.
static methods cannot refer to instance variables and are invoked by using the class name rather than on an instance of the class (MyClass::StaticProcedure()).
static methods will get loaded into memory once we declare the corresponding class.

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...