Presentation is loading. Please wait.

Presentation is loading. Please wait.

Systems Analysis & Design Methods II Coping with complex conditions: II Coping with complex conditions: Decision tables.

Similar presentations


Presentation on theme: "Systems Analysis & Design Methods II Coping with complex conditions: II Coping with complex conditions: Decision tables."— Presentation transcript:

1 Systems Analysis & Design Methods II Coping with complex conditions: II Coping with complex conditions: Decision tables

2 2Systems Analysis II Decision Tables Contents Decision Tables Example Example Context and history Context and history Possible implementations Possible implementations Evaluation & alternatives Evaluation & alternatives

3 3Systems Analysis II Decision Tables Example: Bank account rules I) If a client has an account for over 10 years (ay>10) and his salary is deposited on this account (sd=Y), he gets a bonus of 10000, except if his balance was negative during more than 3 months (nbm>3), in which case his bonus drops to 5000. II) The bonus is 5000 for clients who have an account for more than 3 years, except if their balance was negative for at least 1 month, in which case the bonus drops to 2500. III) No bonus is granted to anyone with a balance that has been negative for over 5 months.

4 4Systems Analysis II Decision Tables Example: Bank account rules variables and categories There are three variables, yielding three variable rows. For every category within a variable, the columns are split up, yielding 3 x 4 x 2 = 24 columns ay: 10 ay: 10 nbm: 5 nbm: 5 sd: Y ; N sd: Y ; N

5 5Systems Analysis II Decision Tables Full, unchecked table:

6 6Systems Analysis II Decision Tables Full, unchecked table: Remarks Contains every possible case. Contains every possible case. Marks with an x only these cases that are mentioned in the text. Marks with an x only these cases that are mentioned in the text. May contain inconsistencies. May contain inconsistencies. E.g. In our example case 15 & 16: you get both 0 and 2500. case 15 & 16: you get both 0 and 2500. J(a) means Y(es). J(a) means Y(es).

7 7Systems Analysis II Decision Tables Checked Table

8 8Systems Analysis II Decision Tables Checked Table: Remarks Maximum one value per column Maximum one value per column Solves consistency poblems. Examples: Case 15 & 16: 0:x, 2500:x -> Choose 0 Case 15 & 16: 0:x, 2500:x -> Choose 0 Reason: Sentence III explicitly states that no one, having a negative balance for over 5 months, is to have a bonus. That’s why we choose 0 and not 2500 as the bonus in case 15 & 16 Case 17: 5000:x, 10000:x -> Choose 10000 Case 17: 5000:x, 10000:x -> Choose 10000 Reason: This time, no sentence is more explicit then another. Common sense tells you to take 10000 …

9 9Systems Analysis II Decision Tables Checked Table: Remarks Minimum one value per column Minimum one value per column If no bonus is granted, we want this to be explicit. We want to avoid blank columns. In our table: Cases 1 to 6: no box marked -> Choose 0 Cases 1 to 6: no box marked -> Choose 0 All other boxes get hyphens. Now, every case (column) is assigned exactly one bonus.

10 10Systems Analysis II Decision Tables Reduced Table

11 11Systems Analysis II Decision Tables Reduced Table: Remarks Since we now have only one x per column, we can move the appropiate bonus-value to the column, reducing the rows. Since we now have only one x per column, we can move the appropiate bonus-value to the column, reducing the rows. Criteria that do not matter, are given a hyphen sign (-), meaning “don’t care”. Examples: Criteria that do not matter, are given a hyphen sign (-), meaning “don’t care”. Examples: Cases 1 to 8: All cases result in 0 bonus no matter what the values of nbm or sd are. The 8 colmuns are merged Cases 1 to 8: All cases result in 0 bonus no matter what the values of nbm or sd are. The 8 colmuns are merged Cases 9 & 10: Given 3 <= ay <= 10 and nbm < 1, Cases 9 & 10: Given 3 <= ay <= 10 and nbm < 1, sd is of no importance anymore … ( Premie means bonus here)

12 12Systems Analysis II Decision Tables Reduced Table with Optimal Condition Order

13 13Systems Analysis II Decision Tables Reduced Table with Optimal Condition Order: Remarks By swapping criteria, some condition testing can be avoided. Just once here: By swapping criteria, some condition testing can be avoided. Just once here: Swapping nbm and sd, reduces the categories from 4 to 3 in the case of ay > 10 Swapping nbm and sd, reduces the categories from 4 to 3 in the case of ay > 10

14 14Systems Analysis II Decision Tables To working code See Customer.java See Customer.java Homework: Homework: Correct possible mistakes Correct possible mistakes Try the three alternatives Try the three alternatives Invent entirely other ways to code it. Invent entirely other ways to code it. Turn the main program to a decent testing program. Turn the main program to a decent testing program.

15 15Systems Analysis II Decision Tables Evaluation and alternatives Problem : repetition of conditional code. Problem : repetition of conditional code. In real life, the same conditions tend to come back in different places in your code. In fact when coding conditional code, you will notice that entire structures of if-then-else nesting come back time after time. This is code repetition or copy-pasting of code, which is a maintenance nightmare.

16 16Systems Analysis II Decision Tables Problem: repetition of conditional code Non OO solution: Write the conditional code in a procedure once and pass function pointers to it. These function pointers enable you to call any function within the complex conditional structure. Non OO solution: Write the conditional code in a procedure once and pass function pointers to it. These function pointers enable you to call any function within the complex conditional structure. N.B. Languages who don’t support function pointers can use eval()-mechanism for evaluation of code, hidden in strings. Or they can use a special case structure to decide which code to call. N.B. Languages who don’t support function pointers can use eval()-mechanism for evaluation of code, hidden in strings. Or they can use a special case structure to decide which code to call. OO solution: Use inheritance in stead of conditions. The polymorphism mechanism removes the need to call function pointers. OO solution: Use inheritance in stead of conditions. The polymorphism mechanism removes the need to call function pointers.


Download ppt "Systems Analysis & Design Methods II Coping with complex conditions: II Coping with complex conditions: Decision tables."

Similar presentations


Ads by Google