第五章 ObjectScript
方法和例程都可以用 ObjectScript 编写,但大多数现代代码都是使用方法编写的。方法包含在类中,这允许将类似的方法分组在一起,在类参考中自动生成文档,以及使用 IRIS 的面向对象功能。
这并不意味着routines 不重要。许多有用的系统实用程序都是作为例程编写的,并且在编译类时会生成例程。
示例类
下面显示了一个名为 User.DemoClass 的示例类,其中包含用 ObjectScript 编写的方法。此示例使我们有机会了解一些常见的 ObjectScript 命令、运算符和函数,并了解代码在方法内的组织方式。
Class User.DemoClass
{
/// Generate a random number.
/// This method can be called from outside the class.
ClassMethod Random() [ Language = objectscript ]
{
set rand=$RANDOM(10)+1 ; rand is an integer in the range 1-10
write "Your random number: "_rand
set name=..png)
.png)
.png)
.png)
.png)

.png)