Psuedocode

profiledjkyce
outlinephase4part2.docx

Phase 5: Using Abstractions in Design

Seeing Abstractions

Throughout this course, we have been realizing the detailed design for the pieces of the whole picture we started with at the beginning of the course. We have built many abstractions, so let’s go back and document what we have found and see the abstractions we have created.

Abstraction Name

Parameter List

Scope/Purpose

calculateSubtotal

(totalPurchaseAmount :double,

salesTaxRate : double)

Applies sales tax and computes the final amount due

<keep going>

Refactoring

Sometimes it is easy to see how the whole solution can be broken into pieces, and other times it is done as you see abstractions and opportunities for reuse in the resulting design. This is called refactoring. For the pseudocode you see below, look for abstractions you could create and create a flowchart using your simplifications.

Psuedocode in Need of Refactoring

Array : namesInSystem

Array : phoneNumbersInSystem

String : nameInput

While (nameInput is not valid)

nameInput = prompt user for input

if (nameInput is provided and not blank)

break out of loop

end loop

Prompt user the input is required and not blank

End loop

Integer : indexForName = -1

For (index = all items in namesInSystem

If (nameInput = namesInSystem[index])

indexForName = index

end if

End loop

If (indexForName = -1)

Prompt user “We cannot find your account, please call us”

Else

String : phoneNumberInput

While (phoneNumber is not valid)

phoneNumber = prompt user for input

if (phoneNumber is provided and not blank)

break out of loop

end loop

Prompt user the input is required and not blank

End loop

If (phoneNumber = phoneNumbersInSystem[indexForName])

Prompt “we found your account welcome”

Else

Prompt “we cannot validate your account, try again later”

End if

End if

Refactored Flowchart

The above pseudocode is long, but you can omit much of the details. You can accomplish the same logic removing more than 30 lines. You do not have to show all of the details removed if moved into an abstraction, simply name the abstraction and define the parameters to be passed to the call replacing the lines of code.

<insert your flowchart here>