| ILOG Rules for .NET User Guides > Walkthroughs > Walkthrough: Creating a Decision Table |
Walkthrough: Creating a Decision Table |
PREVIOUS NEXT |
This walkthrough presents the following fundamental procedures for creating a decision table with ILOG Rule Studio for .NET:
In this walkthrough you create a console application that uses a decision table to select a message to display in a command window.
Setting up the application involves creating a solution and defining the classes that model the items of interest in the business domain. You import these classes into the business object model so that you can use them to write rules.
The Message class:
using System;
namespace ClassLibrary1{
// Class to print a message
public class Message
{
// Prints a message to the console
public void PrintMessage(string msg)
{
Console.WriteLine(msg);
}
}
}
Imports System
' Class to print a message
Public Class Message
' Prints a message to the console
Public Sub PrintMessage(ByVal msg As String)
Console.WriteLine(msg)
End Sub
End Class
The Customer class:
using System;
namespace ClassLibrary1{
//A class for holding customer information
public class Customer
{
//Constructor
public Customer(int age, bool hasAccount)
{
this.age = age;
this.hasAccount = hasAccount;
}
// The age of the customer
private int age;
public int Age
{
get { return age; }
}
// Test if the customer has an account.
private bool hasAccount;
public bool HasAccount
{
get { return hasAccount; }
}
}
}
Imports System
' A class for holding customer information
Public Class Customer
Private m_age As Integer
Private m_hasAccount As Boolean
'Constructor
Public Sub New(ByVal age As Integer, ByVal hasAccount As Boolean)
Me.m_age = age
Me.m_hasAccount = hasAccount
End Sub
'The age of the customer
Public Property Age() As Integer
Get
Return m_age
End Get
Set(ByVal Value As Integer)
m_age = Value
End Set
End Property
'Test if the customer has an account
Public Property HasAccount() As Boolean
Get
Return m_hasAccount
End Get
Set(ByVal Value As Boolean)
m_hasAccount = Value
End Set
End Property
End Class
Business Element |
Display Text |
|---|---|
Message |
message |
PrintMessage(msg) |
print {this}: {0} |
Customer |
customer |
get_Age() |
the age of {this} |
get_HasAccount() |
{this} has an account |
To create the decision table you:
Now the decision table is ready to be populated.
Now the table is populated, however, you still need to consider the cases for customers that have accounts with ages less than 18 and more than 65. You can also make the table a little easier to read by removing the unwanted cells and adjusting the alignment of the text.
The final decision table should now look something like this:
To define the application logic you:
using System;
using System.IO;
using ILOG.Rules;
using ClassLibrary1;
namespace ConsoleApplication1 {
public class RuleExecuter {
public static void Main() {
// Create a rule engine in which to execute the ruleset.
RuleEngine engine = new RuleEngine();
// The message containing the promotion information.
Message promotion = new Message();
// The customers to be considered.
Customer jack = new Customer(72, true);
Customer nandira = new Customer(16, false);
Customer laurel = new Customer(45, true);
Customer felix = new Customer(23, true);
// Add objects to the rule engine's working memory.
engine.Assert(promotion);
engine.Assert(jack);
engine.Assert(nandira);
engine.Assert(laurel);
engine.Assert(felix);
// Load the ruleset into the rule engine.
engine.RuleSet = new BusinessRules1();
// Execute the ruleset.
engine.Execute();
//Get the user's input to quit the application.
Console.WriteLine();
Console.WriteLine("To exit, press ENTER.");
Console.In.ReadLine();
}
}
}
Imports System
Imports System.IO
Imports ClassLibrary1
Imports ILOG.Rules
Module Module1
Sub Main()
' Create a rule engine in which to execute the ruleset.
Dim engine As New RuleEngine
' Load the ruleset into the rule engine.
engine.RuleSet = New BusinessRules1
' The message containing the promotion information.
Dim promotion As New Message
' The customers to be considered.
Dim jack As New Customer(72, True)
Dim nandira As New Customer(16, False)
Dim laurel As New Customer(45, True)
Dim felix As New Customer(23, False)
' Add objects to the rule engine's working memory.
engine.Assert(promotion)
engine.Assert(jack)
engine.Assert(nandira)
engine.Assert(laurel)
engine.Assert(felix)
' Execute the ruleset.
engine.Execute()
' Get the user's input to quit the application.
Console.WriteLine()
Console.WriteLine("Press ENTER to exit.")
Console.In.ReadLine()
End Sub
End Module
You can test the business rule application within Visual Studio.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |