Table of Contents

Automating the Connection of Business Rules in Object-Oriented Applications using AOP

Type: Thesis and Apprenticeship Project

Assistants: María Agustina Cibrán,Maja D'Hondt
Supervisor: Viviane Jonckers

Part of Thesis and/or Apprenticeship Projects 2004-2005

Student

fabriceosteaux.jpg
Fabrice Osteaux
Program: 4th year Applied Computer Science
E-mail: faosteau@vub.ac.be
Mobile: +32-(0)486504424

Description

Business Rules ought to be loosely coupled from the core application they relate to, and could be created and managed by non technically-skilled people, to achieve this:

To achieve this, the ideas of 1) (language specification and BR linking wizard) will be used

Current Status

Completed

In Progress

Open Issues

CONNECT <BR NAME> AT <EVENT> [WHERE <EVENT CONTEXT ITEM NAME> [IS <LOCALNAME>]]
[ CAPTURE AT <EVENT> [WHERE <EVENT CONTEXT ITEM NAME> AS <LOCALNAME>],
          ...]
[ MAPPING <LOCALNAME> TO <BRNAME> ]

Having a Capturespecifier is not really adequate: it breaks the high-level abstraction offered by the domain model entities (events, business rules, …) by using a low-level specification of the capture point, which should be avoided. Possible alternatives are:

  1. (Define capture points entities stored in DM)
  2. Add semantic to context entities associated with an event (choose and names event's available context items (parameter, returnvalue, …)

After a first discussion on the issue, it has been decided to select, and add names to context objects available at events, this being added to the domain model.

Example of Business Rule translation

The following Business rule:

If a cutomer has bought more than a certain quantity of products or a certain amount of money, then he gets a discount and becomes a frequent customer.

translated in high level language:

BR FrequentCustomer

PROPS double AS targetamount,
      int    AS minquantity,
      double AS discount,
      String AS newstatus

USING Shop           AS store,   
      Customer       AS targetcustomer,
      ShoppingBasket AS basket
 
WHERE accounts       IS store.getShopAccounts(),
      shopaccount    IS accounts.getShopAccount(accounts.findShopAccount(targetcustomer)),
      amountspent    IS shopaccount.getAmountSpent(),
      boughtproducts IS shopaccount.getBoughtProducts()

IF    amountspent >= targetamount
      OR boughtproducts >= minquantity
     
THEN  basket.setDiscountRate(discount) 
      AND shopaccount.becomeFrequent()
      AND targetcustomer.setCustomerName(newstatus)

Running the translator generates the following java code:

//Automatically Generated Business Rule
public class FrequentCustomer
{
  //Properties
  double targetamount;
  int minquantity;
  double discount;
  java.lang.String newstatus;
 
  //Business Objects
  ecommerce.Shop store;
  ecommerce.Customer targetcustomer;
  ecommerce.ShoppingBasket basket;
 
  //Business Objects Attributes/Properties
  ecommerce.ShopAccounts accounts;
  ecommerce.ShopAccount shopaccount;
  int amountspent;
  int boughtproducts;
 
  //Constructor
  public FrequentCustomer(double targetamount, int minquantity, double discount, java.lang.String newstatus)
  {
    this.targetamount = targetamount;
    this.minquantity = minquantity;
    this.discount = discount;
    this.newstatus = newstatus;
  }
 
  //Fires the BR
  public void applyRule(ecommerce.Shop store, ecommerce.Customer targetcustomer, ecommerce.ShoppingBasket basket)
  {
    //initialize bo data members
    this.store = store;
    this.targetcustomer = targetcustomer;
    this.basket = basket;
    //initialize bo attributes aliases
    this.accounts = store.getShopAccounts() ;
    this.shopaccount = accounts.getShopAccount(accounts.findShopAccount(targetcustomer)) ;
    this.amountspent = shopaccount.getAmountSpent() ;
    this.boughtproducts = shopaccount.getBoughtProducts() ;
 
    if (condition())
    {
      action();
    }
  }
 
  private boolean condition()
  {
    return ( ( amountspent >= targetamount ) || ( boughtproducts >= minquantity ) );
  }
 
  private void action()
  {
    basket.setDiscountRate(discount);
    shopaccount.becomeFrequent();
    targetcustomer.setCustomerName(newstatus);
  }
}

Apprenticeship Documents

Links

1) Tool support for linking Business Rules to OO applications using AOP, J. Elsocht, 2004 (Thesis)