Using Read-Only Properties
PeopleCode read-only properties are functionally similar to static variables, as long as the class that defines the properties initializes them and does not change them. The difference is that you need an instance of the class to access them.
For example, consider a Category object that has a CategoryType member that can have one of the following values:
-
‘R’ for Regular
-
‘B’ for Browse
-
‘N’ for News
You can define three read-only properties corresponding to each of these values, REGULAR, BROWSE, and NEWS, then initialize them to the appropriate values in the constructor of the class.
When you write code to evaluate the CategoryType of the Category object, perform a test like this:
If (&category.getCategoryType() = &constants.NEWS) then...PeopleSoft recommends referring to the read-only properties, rather than their literal values, for the following reasons:
-
If you spell a literal value incorrectly, the PeopleCode editor does not catch it; if you spell a read-only property wrong, it does.
-
If you ever need to change the value of a read-only property, you only have to do it in one place.
-
It makes the code more maintainable and reusable (because NEWS is more intelligible than ‘N’).