Home > Software Design and Development > Core > Software Development Cycle > Stubs and flags
This material demonstrates the use of stubs and flags to test the way modules work together before the building phase of the program development cycle is complete.
H4.3 A student applies a modular approach to implement well-structured software solutions and evaluates their effectiveness.
Students learn about program development techniques in software solutions such as using stubs and flags (Syllabus document, p. 43).
The following headings will help you navigate.
Good programming uses subprograms or modules to perform single tasks. This is easier to debug, more conducive to a team approach and easier to maintain. To test whether all the modules will work together, before all the modules are coded, small modules can be created to represent parts of the program yet to be written. These are called stubs. Stubs may be used to:
In this example, stubs are used to test the menu module of a program. The menu consists of five choices: addition, subtraction, multiplication, division or exiting the program. The procedures for adding, subtracting, multiplying and dividing have not yet been written. In this pseudocode algorithm, stubs displaying the option chosen replace them. This tests the logic of the algorithm. When coded and tested, the programmer will know that the menu is working by seeing the correct display. Code modules will replace the display stubs as they are written.
| BEGIN |
menu |
|
|
|
get menuOption from user WHILE menuOption is not ´E´ |
|
|
|
|
CASEWHERE menuOption is ´A´: display “Addition” ´D´: display “Division” ´M´: display “Multiplication” ´S´: display “Subtraction” OTHERWISE display “Choose A, D, M, S or E only” ENDCASE |
|
|
get menuOption from user ENDWHILE |
|
| END |
menu |
|
assign test values to variables before input modules have been written.
In an algorithm to sum a 4-element array of integers a series of assignment statements is used to set test values to variable stubs in place of an input module not yet written.
|
BEGIN |
IntegerSum |
|
|
set array[0] = 12 set array[1] = 69 set array[2] = -4 set array[3] = 0 set sum = 0 FOR index from 0 to arraySize sum = sum + array[index] NEXT index display sum |
|
END |
IntegerSum |
In complex programs, it is sometimes helpful to know whether a certain condition has been met, (e.g. has a delete module been used), and to act on that condition later in the program. A flag is a variable that is used to indicate whether an event has occurred or not. Flags are often Boolean variables set as false at the beginning of the program. Flags are particularly useful in program testing to determine whether a particular piece of code has been called.
Write an algorithm for a logon module that requests a user’s identity and password. If the user is a new user, control passes to the new user module for registration. For a registered user, control passes to the security module that verifies access rights before allowing access to the program. Write the pseudocode algorithm using display stubs to represent the new user and security (registered) user modules.
Fowler, A (2000). Heinemann software design and development Preliminary Course. Heinemann, Port Melbourne, Victoria.
This work was prepared by Beverley Sampford