< Previous | Next >

Task 4: Choosing an implementation class for an interface

You define the implementation class for an interface.

About this task

In this task, you want to add a new input parameter to define what kind of property the borrower has. You add a new propertyInfo attribute in the Borrower class. The attribute is typed with an interface, and you must choose the implementation class to be used in the tests.

The PropertyInfo interface has two implementation classes: CommercialPropertyInfo and CondominiumPropertyInfo.

In the BOM, you must create a constructor for the interface to:

  • Choose the implementation class to use for the tests.
  • Define the arguments that create the columns in the Scenarios sheet.

Procedure

  1. Integrate the new attribute in the XOM:
    1. Switch to the Java™ perspective.
    2. Open loanvalidation-xom/src/loan/Borrower.java.

      The propertyInfo attribute has the following comments:

          /* Uncomment for Step4
      	private PropertyInfo propertyInfo;
      
      	public PropertyInfo getPropertyInfo() {
      		return propertyInfo;
      	}
      	public void setPropertyInfo(PropertyInfo info) {
      		propertyInfo = info;
      	}
          End Uncomment for Step4*/
    3. Uncomment the propertyInfo attribute by removing the comments /* Uncomment for Step4 and End Uncomment for Step4*/.
    4. Save the changes.
  2. Update the BOM:

    Now that you have modified your XOM, you must update the BOM accordingly.

    The type of the new attribute is an interface. You must create a constructor for the interface to define its implementation class in a test or simulation.

    1. Switch to the Rule perspective.
    2. In the Rule Explorer, right-click loanvalidation-rules/bom/model/loan/Borrower, and then click BOM Update to display the BOM Update view.
    3. In the BOM Update view, click the Differences and Actions section to display the Update the BOM class "loan.Borrower" action.
    4. Click Perform and save to perform the action.
    5. Click Finish in the Verbalize BOM dialog.
    6. A new propertyInfo attribute is created in the Borrower BOM class.
  3. Create a constructor for the PropertyInfo interface:

    To check that the new property info input parameter appears in the Scenarios sheet, you generate the Excel scenario file template.

    1. In the Rule Explorer, double-click the PropertyInfo interface (loanvalidation-rules > bom > model > loan > PropertyInfo).
    2. In the Members area, click New.
    3. In the New Member dialog, select Constructor.
    4. Click Add, and then enter the following parameters in the Method Argument dialog:
      • Name: type
      • Type: java.lang.String
    5. Do the same for the following arguments:
      • Name: propertyType, Type: java.lang.String
      • Name: numberOfBedrooms, Type: int
      • Name: numberOfBathrooms, Type: int
    6. Click Finish, and double-click the new constructor to edit it.
    7. In the BOM to XOM Mapping section, type the following code to define the implementation class:
      if (type == "Commercial")
         return new loan.CommercialPropertyInfo(propertyType);
      else 
         return new loan.CondominiumPropertyInfo(numberOfBedrooms, numberOfBathrooms);
    8. Save the changes.
  4. Generate the Excel scenario file template:
    1. In the Rule Explorer, right-click the loanvalidation-rules project, and then click Decision Validation Services > Generate Excel Scenario File Template.
    2. Keep the default options as you did in the previous tasks.
    3. On the Expected Results page, expand the loan report, select approved and first message, and then click Next.
    4. Click Finish.
    5. In the Rule Explorer, double-click testsuite.xls to open it.

      The new property info input parameter appears in the Scenarios sheet. Four new columns define the property of the borrower:

      • type
      • property type
      • number of bedrooms
      • number of bathrooms
    6. Close testsuite.xls.

What to do next

In the next task, you add a domain to the property of the borrower and see how to maintain it in the scenario file.

< Previous | Next >