ルール・アクション

ルール・アクションでは、ルールの if 部分が true または false の場合に実行すべき内容を定義します。

アクションは、ルールの then 部分と else 部分で定義します。 ルール・アクションは、ルールの if 部分が true の場合にルールが実行する 1 つ以上のアクション語句で構成されます。 また、ルール・アクションには、ルールの if 部分が false の場合に実行するアクション語句を含めることもできます。

アクションは、ルールの次の部分で定義します。

ルールの then 部分では、1 つ以上のアクションを定義する必要があります。 then 部分または else 部分に複数のアクションが含まれる場合、ルールは、それらがリストされている順にアクションを実行します。

then 部分の例

次のルールは、shopping cart の値が $100 より大きい場合にのみ 15% の割引が適用されます。それ以外の場合は、ルールは何もアクションを適用しません。

if 
	the value of the shopping cart is more than $100 
then 
	apply a 15% discount on the shopping cart; 

else 部分の例

次のルールは、条件が満たされた場合は変更を適用し (then)、条件が満たされなかった場合は別の変更を適用します (else)。

if 
	'the loan report' is approved 
	and the loan grade in 'the loan report' is one of { "A", "B", "C" } 
then 
	in 'the loan report', accept the loan with the message "Congratulations! Your loan has been approved"; 
else 
	in 'the loan report', refuse the loan with the message "We are sorry. Your loan has not been approved";

メソッドを呼び出すアクションの例

アクション・ステートメントは、ビジネス用語でメソッドを呼び出すことができます。 ルール語彙のアクション語句を使用することでメソッドを実行します。 メソッドは、静的メソッドでもクラスのメンバーでも構いません。

以下のアクション・ステートメントは apply を使用して applyDiscount メソッドを呼び出し、 display を使用して displayMessage メソッドを呼び出します。

then 
	apply a 10% discount; 
	display the message: "You received a discount!";