October 17, 2013

Method Modifiers Supported by X++

 Method Modifiers Supported by X++


Method Modifiers Supported by X++
Modifier
Description
static
Static methods are accessed via class declarations. Fields can’t be accessed from within a static method.
final
Final methods can’t be overridden by methods with the same name in derived classes.
abstract
Abstract methods have no implementation. Derived classes must provide definitions for abstract methods.
server
Server methods can execute only on an Application Object Server. The server modifier is allowed only on static methods.
client
Client methods can execute only on a MorphX client. The clientmodifiers are allowed only on static methods.
display
Display methods are invoked each time a form or report is redrawn. The display modifier is allowed only on table, form, form data, report, and report design methods.
edit
The edit method is invoked each time a form is redrawn or a user provides input through a form control. The edit modifier is allowed only on table, form, and form data source methods.


For More Details on the same check below link

Abstract Class and Abstract Method in AXapta

     Abstract Class and Abstract Method

Abstract Class:
When we declare a class as abstract, this class cannot initiate in X++ code. To use this class or its method we have to first extend this class than only we are able to use this class or its method. To understand the abstract class consider following example
We have three classes
     1.      absClass  (it’s an abstract class)
     2.      normalClass (an another class which will use the absClass methods)
     3.      extendAbsClass (this class will extends the absClass)

    1.      abstract class absClass
     {
     }

    void printName()
   {
    ;    info("AbsClass... Deepak"); 
   }


    2.      class extendAbsClass extends absClass
{
}

    3.      class normalClass
{
}

  void accessAbsClass()
{
    absClass        absClass;
    extendAbsClass  extendAbsClass;
    ;
 //   absClass = new absClass();    // this declaration will throw error “Object could not be created because class absClass is abstract” so first we extend absClass into extendsAbsClass and further use extendsAbsClass to access absClass methods.
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.printName();
}


Abstract Method:

When we declare a method as abstract , this method should be overload in child class or we can say , this method  should be declare/initiate in child class, than only we can use this class or its method.
Note:
a.      Abstract methods may only be declared in abstract classes.
b.      No code or declarations are allowed in abstract methods.

We have three classes
i.                    absMethodClass
ii.                  extendAbsClass
iii.                NormalClass

1.      abstract class absMethodClass
{
}

abstract void absPrintName()
{
                        // we cannot declare any code in abstract method
}

2.      class extendAbsClass extends absMethodClass
{
}

void absPrintName()
{
    ; // we have to initiate abstract method here as this class extends the abstract class.
    info("abstract method declaration in derived class");
}
3.      class childClass_1
{
}

void accessAbsClass()
{
    extendAbsClass  extendAbsClass;
    ;
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.absPrintName();

}


- Harry