Add code and methods to meet business requirements

Completed

Finance and operations apps use X++ development language in its classes. X++ is an object-oriented language. If you haven't used it before, but are familiar with another object-oriented language, you will find it easy to learn.

After you create a class from Solution Explorer, you can add code to the class. Data provides the state of an object, while a method provides behavior to an object. Methods that you will encounter and create in development for finance and operations apps include:

  • New method - Creates an instance of the class by using the new keyword. The default constructor is new(). The following is an example of declaring a variable and creating an instance of an object by calling the new method:

    Sample mySample; //this declares a variable to refer to a sample object
    
    mySample = new Sample(); //this creates an instance of a sample object
    
  • Finalize method - A destructor method that finalizes an instance of a class by using the finalize keyword. The following is an example, using an if statement, which shows how to call a finalize method:

    if (condition) //state the condition that should be met
    {
      this.finalize();
    }
    
  • Main method - Creates an instance of an object and calls the required member methods. It is a class method that is run directly from a menu option. To transfer data to the method, use the _args parameter. The following is an example of the syntax that is used to define a main method:

    Static void main (Args _args)
    {
    	//This comment represents where you would insert your code.
    }
    
  • Instance method - Also referred to as an object method, it is embedded in each object that is created from the class that contains the instance method. Before you can use the method, you must instantiate that object. The following is an example of the syntax that is used to call an instance method:

    ClassName objectReference = new ClassName();
    objectReference.methodname();
    
  • Static method - Also referred to as a class method, it uses the static keyword and belongs to a class. With a static method, unlike with an instance method, you don't need to instantiate an object before you use the method. Static methods are commonly used to work with data that is stored in tables. The following is an example of the syntax that is used to call a static method:

    ClassName::methodName();
    

Accessor keywords can be used to control whether the methods in other classes can call the methods in your class. Class inheritance is also affected by the following accessor keywords.

  • public - Methods declared as public can be called from anywhere that the class is accessible. A public method can be overridden by a subclass, unless that method is declared as final.

  • protected - Methods declared as protected can only be called from methods in the same class or methods in a subclass of that class. A protected method can still be overridden in a subclass.

  • private - Methods declared as private can only be called from methods within the same class. Unlike public and protected methods, private methods can't be overridden in a subclass.