Difference between Parameter and Property
Hi Community,
I am new to ensemble and cache object scripts ,i am trying to create a business service using Ens.BusinessService
but i have doubt what is the difference or uses between Parameters and property in defining classes in defining business service
Joe
Comments
A parameter is a shared, constant value that's available to all instances of a class. It can be calculated when the class is compiled, but it generally can't be altered at runtime.
A property is a variable that each instance of a class stores it's own value for, and it can be set changed at runtime.
Parameter values are static values* and the same for all objects.
Property values are different for each object.
Small example:
Class Circle Extends%RegisteredObject {
Parameter PI = 3.14;Property Radius;
Method GetArea()
{
quit ..#PI * ..Radius * ..Radius
}
ClassMethod Test()
{
set circle = ..%New()
set circle.Radius = 25write circle.GetArea()
}
}* parameters can be calculated but not set by user.
I won't repeat the excellent definitions already provided, but can share some examples of class parameters where we use them:
Parameter FILES = "/files";Parameter INSTANCE As COSEXPRESSION = "$p($SYSTEM, "":"", 2)";Parameter RUNLEVEL As COSEXPRESSION = "$li($lb(""dev"",""Test"",""LIVE""), $lf($lb(""HCDEV"",""HCTEST"",""HCLIVE""), ..#INSTANCE))";We use ..#FILES to prefix or normalize a directory off the top-level filesystem on the server.
We use ..#INSTANCE if we need to identify which IRIS instance, like in an email message, it came from.
We use ..#RUNLEVEL in conditionals or pass as a parameter, where we might want code only to run on "Test" or "LIVE".
Hi ,
Thank you for sharing very important things about parameter and property
I have one doubt while creating the custom business service i am using EnsLib.File.InboundAdapter like below
Parameter ADAPTER = "EnsLib.File.InboundAdapter";
1.I just want to know it means the methods exits in EnsLib.File.InboundAdapter class can i use them in my custom class by
2.By adding .. 2 dots like below we can access the methods exists in the class ?
.png)
Joe
Hi Joe,
The 2 dots syntax is used to access the properties and methods of the current object. You can also use $this to access the current object.
For example, if you have a class called "MyClass" and you have a property called "MyProperty" in that class, you can access the property value by using the following syntax:
User.MyClass Extends EnsLib.BusinessService
{
Property MyProperty;
Method MyMethod()
{
set ..MyProperty = 10;
set $this.MyProperty = 10;
}
}
In your case, you can use the following syntax to access the methods of the EnsLib.File.InboundAdapter class:
User.MyClass Extends EnsLib.BusinessService
{
Parameter ADAPTER = "EnsLib.File.InboundAdapter";
Property Adapter = "EnsLib.File.InboundAdapter";
Method MyMethod()
{
do ..Adapter.AdapterMethod()
do $this.Adapter.AdapterMethod()
}
}
Hope this helps.