Constructors

Best Practices for Static Construct Methods 

You should create a static construct method for each class. Warning icon The method should return an instance of the class.
The construct method must be:
  • static
  • named "construct"
In most cases the construct method should be public. If the class is instantiated using a newParameter method, then declare the construct method as private. The method should return an instance of the class and contain no other code. construct methods should not have any parameters, or else should have the same parameters as the defaultnew constructor (it is recommended that you do not have parameters on new). Warning icon
If your class declaration contains parameters, use a static new method as the constructor and use the construct method within the static new method to create an instance of the class.

Best Practices for Constructors


how to create a clean inheritance model and minimize problems when code is upgraded:
  • Each class must have a single public construction method unless the class is abstract. If no initialization is required, use a static construct method. Otherwise, use astatic new… method (the default constructor (new method) for the class should be protected).
  • Each class should have at least one static construct method method. Warning icon
  • Each class should have at least one static new… method.
  • Each class should have a new method (the default constructor). This method should be protected. Warning icon
  • Create accessor methods to get and set class variables.
  • Create init methods to carry out any specialized initialization tasks that should be carried out after instantiation.
main :Classes that are invoked from a menu have theirmain method called by the system.
new :The new keyword is used to allocate a new instance of a class. Then the constructor is automatically called.
Each class has exactly one constructor, and the constructor is named new. You can decide what parameters the constructor should input.
finalize :The Object class contains the finalize method. The finalize method is not final, and it can be overridden.
The finalize method appears to resemble theSystem.Object.Finalize method in C#, but in X++ the finalize method has no special meaning of any kind.
An object is automatically removed from memory when the last reference to the object stops referencing the object. For example, this can happen when the last reference goes out of scope or is assigned another object to reference.
super : The super keyword is used in a derived class to access the same method on its base class.
void method2()
{
;
// Call method2 method
// on the base class.
super();
}

this :
For a call from one instance method to another on the same object, a qualifier for the called method is required. The keyword this is available as a qualifier for the current object.

Comments

Popular posts from this blog

Dynamics Ax 2012 Interview Questions:

Oops concept in AX