Skip to main content

This documentation is for an older version of this product. See the latest version of this content.Opens in a new tab

クラス・メソッド

ここでは、簡単ですが重要な、複数のクラス・メソッドで構成される ObjectScript クラス定義 (ObjectScript.RightTriangle) について学習します。まだすべてを完全には理解できなくても心配ありません。ここをクリックすると、詳細な説明が表示されます。

Main()IsNegative()Compute() を呼び出します。これらのクラス・メソッド内には、以下の例があります。

  • WriteReadSetDoReturn、および Quit の各コマンド

  • If/Else および Do/While の文

  • 後置条件: Quit と、それに続くコロンと条件

  • $Justify$Case、および $Zsqr の各関数

  • システム・ルーチン %D および %T の呼び出し

メソッドはクラス定義に含まれ、VS Code - ObjectScript を使用して記述されています。最も単純な形式では、クラス定義は以下のような外観で、1 つまたは複数のクラス・メソッドが含まれています。

VS Code - ObjectScript


/// description of class goes here, must start with 3 slashes
Class PackageName.ClassName
{

/// description of method goes here, must start with 3 slashes
ClassMethod MethodName(arg1 as type1, arg2 as type2) as returntype
{
    // ObjectScript goes here (this is actually a comment)
}

}

これらの一連のメソッドで、直角三角形の両辺の長さを基に面積と斜辺を計算します。また Main() クラス・メソッドは、現在の日付と時刻を表示します。Main() を呼び出してコードを実行してみましょう。

ターミナル


USER>do ##class(ObjectScript.RightTriangle).Main()

Compute the area and hypotenuse of a right triangle
given the lengths of its two sides.
 
First, choose a unit of measurement:
1) inches
2) feet
3) miles
4) centimeters
5) meters
6) kilometers
 
Option? 1
 
Length of side 1: 3  Accepted.
Length of side 2: 4  Accepted.
 
The area of this triangle is 6.00 square inches.

The hypotenuse is 5.00 inches.

Current date: Jan 10 2018
Current time: 2:42 PM
USER>

FeedbackOpens in a new tab