Static Construct():
This method returns an instance of the class. It is a best practice to have a construct method in your class. This method should always be static but can be public or private depending upon the use. When calling a class from another class or job construct method can be used for this
Example:
To give you an example, let assume that we have a class ‘AsimConstructClass’ and have a variable ‘Name’ having a parmName method to be set or get
Here I have create a construct method from template, which is returning the instance
I have also create a run method for my logic in a class
Now, finally I have created a job and in this I will get the instance of the class and call the run method in a single call
Static New():
Basically new method is the default constructor of a class invoke when user uses ‘new’ keyword. Mostly it is protected like.
But in some cases we can create our own static new method like
The above example for construct method, shows an infolog with the name ‘Asim’ which is a hardcoded value in a class, So now what if a user wants to send some input from a another class or job. In order to do this we can create your own individually named static new… methods with different parameter profiles and make it public static
Here newName takes a parameter,
Also in the newName code, it is initializing the instance by calling the construct() method which should be private in this case ,so I made it private
And now in the job I did this
Finally on running it will show
No comments:
Post a Comment