Note: Role lists suitable for novice use can be found in the page describing how roles can be utilized in teaching.
Procedural programming: Roles apply to variables, and parameters.
Object-oriented programming: Roles apply to variables, parameters, atttributes, and objects that encapsulate a single conceptual attribute.
Functional programming: Roles apply to the recursive behavior of parameters and return values
Notes that are in italics describe special cases and can be skipped on first reading. Technical definitions and properties provide more exact information about the roles, and they are not expected to be used in, e.g., teaching programming to novices.
Technical definitions may be needed in, e.g., role analysis. They are meant for human classifiers who are able to use their understanding of a program to capture the data flow through a data entity and identify main phases of this flow. For example, a one-way flag may be reset to its initial value at the beginning of the main loop (and changed within a nested loop) yielding the one-way behavior within the main loop even though the flag goes both ways during the entire program execution.
Properties are descriptions of actual use in novice-level programs or consequences of the technical definitions. They can be used in, e.g., devising pictorial representations for roles.
Roles can be grouped acording to the way they relate to data flow:
Fixed value and organizer contain the same data throughout the program; only the order of data elements may be changed. Most-recent holder and stepper record data flow sources; either coming from outside or generated internally. The net effect of all items in a data flow is represented by a one-way flag, most-wanted holder, or gatherer; while a manipulation of a single element is recorded in a transformation, follower, or temporary. Finally, a data entity not covered by any of the previous roles is considered to have the role other.
The roles are described in the following order:
The role images are examples only. In actual use, they should be replaced by images better suiting the cultural backgrounds of users.
Fixed value (aka Constant)
A data entity whose value does not change after initialization. |
Procedural example:
program fuelRate; var start, finish: integer; fuel: real; begin write('Enter fuel amount: '); readln(fuel); write('Enter odometer at start: '); readln(start); write('Enter odometer at finish: '); readln(finish); while finish <= start do begin write('Odometer cannot be smaller at finish. Re-enter: '); readln(finish) end; writeln('Average rate of fuel consumed was ', fuel / (finish - start) ) end.
(All roles in the program: start - fixed value | finish - most-recent holder | fuel - fixed value)
Object-oriented example:
public class Dog { String name; int age; public Dog (String n) { name = n; age = 0; } public void birthday () { age++; } }
(All roles in the class: name - fixed value | age - stepper)
Examples of use:
Notes:
write('Enter fuel amount: '); readln(fuel); if fuel < 0 then begin fuel := abs(fuel); writeln('Using ', fuel, ' instead.') end; ...
Technical definition:
Properties:
|
Organizer
An array which is only used for rearranging its elements after initialization. |
Procedural example:
program bubbleSort; var i, j, temp: integer; a: array [1..10] of integer; begin for i := 1 to 10 do begin write('Enter number: '); readln(a[i]); end; for i := 1 to 9 do for j := i+1 to 10 do if a[i] > a[j] then begin temp := a[i]; a[i] := a[j]; a[j] := temp end; for i := 1 to 10 do writeln(a[i]) end.
(All roles in the program: i - stepper | j - stepper | temp - temporary | a - organizer)
Object-oriented example:
public class ReversableString { private String string; public ReversableString (String s) { string = s; } public String get() { return string; } public void reverse() { char[] chararray = string.toCharArray(); int length = string.length(); char tmp; for (int i = 0; i<length/2; i++) { tmp = chararray[i]; chararray[i] = chararray[length-i-1]; chararray[length-i-1] = tmp; } string = new String(chararray); } }
(All roles in the class: string - organizer | s - fixed value | chararray - organizer | length - transformation | tmp - temporary | i - stepper)
Examples of use:
Notes:
Technical definition:
Properties:
|
Stepper
A data entity stepping through a succession of values that can be predicted as soon as the succession starts. |
Procedural example:
program monthlySales; var month, largest: integer; sales: array [1..12] of integer; begin for month := 1 to 12 do begin write('Enter sales of month ', month, ': '); readln(sales[month]) end; largest := sales[1]; for month := 2 to 12 do if largest < sales[month] then largest := sales[month]; for month := 1 to 12 do begin writeln('Month ', month, ' gave ', largest-sales[month], ' less than the best month.') end end.
(All roles in the program: month - stepper | largest - most-wanted holder | sales - fixed value)
Object-oriented example:
public class Dog { String name; int age; public Dog (String n) { name = n; age = 0; } public void birthday () { age++; } }
(All roles in the class: name - fixed value | age - stepper)
Examples of use:
count := 0; while ... do begin count := count + 1; ... end
size := numberOfItems; while size >= 1 do begin size := size / 2; ... end
Notes:
for density := 10 to 1 do begin scanPoint := density; while scanPoint < areaBorder do begin ... scanPoint := scanPoint + density end end
(In this example, density is also a stepper.)
Technical definition:
Properties:
|
Most-recent holder
A data entity holding the latest value encountered in going through a succession of values. |
Procedural example:
program fuelRate; var start, finish: integer; fuel: real; begin write('Enter fuel amount: '); readln(fuel); write('Enter odometer at start: '); readln(start); write('Enter odometer at finish: '); readln(finish); while finish <= start do begin write('Odometer cannot be smaller at finish. Re-enter: '); readln(finish) end; writeln('Average rate of fuel consumed was ', fuel / (finish - start) ) end.
(All roles in the program: start - fixed value | finish - most-recent holder | fuel - fixed value)
Object-oriented example:
public class BankAccount { private String accountNumber; private float interest, balance=0; public BankAccount (String nr, float percent) { accountNumber = nr; interest = percent; } public String getAccountNumber () { return accountNumber; } public float getBalance () { return balance; } public float getInterest () { return interest; } public void setInterest (float pc) { interest = pc; } public void transaction (float amount) { balance += amount; } }
(All roles in the class: accountNumber - fixed value | interest - most-recent holder | balance - gatherer | nr - fixed value | percent - fixed value | pc - fixed value | amount - fixed value)
Examples of use:
Notes:
while not eof(timesInSeconds) do begin read(timesInSeconds, time); time := time * 1000; (* convert to milliseconds *) ... end
Technical definition:
Properties:
|
Gatherer
A data entity accumulating the effect of individual values in going through a succession of values. |
Procedural example:
program sales; var month, monthSales, totalSales: integer; begin totalSales := 0; for month := 1 to 12 do begin write('Enter sales of month ', month, ': '); readln(monthSales); totalSales := totalSales + monthSales end; writeln('Total sales were ', totalSales) end.
(All roles in the program: month - stepper | monthSales - most-recent holder | totalSales - gatherer)
Object-oriented example:
public class BankAccount { private String accountNumber; private float interest, balance=0; public BankAccount (String nr, float percent) { accountNumber = nr; interest = percent; } public String getAccountNumber () { return accountNumber; } public float getBalance () { return balance; } public float getInterest () { return interest; } public void setInterest (float pc) { interest = pc; } public void transaction (float amount) { balance += amount; } }
(All roles in the class: accountNumber - fixed value | interest - most-recent holder | balance - gatherer | nr - fixed value | percent - fixed value | pc - fixed value | amount - fixed value)
Examples of use:
cardsInHand := 0; while ... do begin ... if taking_new_cards then begin cardsInHand := cardsInHand + numberOfNewCards end ... if putting_away_cards then begin cardsInHand := cardsInHand - numberOfDiscardedCards end ... end
value := 0; read(c); while (c >= '0') and (c <= '9') do begin value := value * 10 + ord(c) - ord('0'); read(c) end
Notes:
Technical definition:
Properties:
|
Most-wanted holder
A data entity holding the best value encountered so far in going through a succession of values. |
Procedural example:
program monthlySales; var month, largest: integer; sales: array [1..12] of integer; begin for month := 1 to 12 do begin write('Enter sales of month ', month, ': '); readln(sales[month]) end; largest := sales[1]; for month := 2 to 12 do if largest < sales[month] then largest := sales[month]; for month := 1 to 12 do begin writeln('Month ', month, ' gave ', largest-sales[month], ' less than the best month.') end end.
(All roles in the program: month - stepper | largest - most-wanted holder | sales - fixed value)
Object-oriented example:
public class Thermometer { private int reading=-999, previous=-999, coldest=-999; private boolean frozen=false; public Thermometer () { } public int getReading () { return reading; } public void setReading (int r) { if (r < coldest) coldest = r; if (r < 0) frozen = true; previous = reading; reading = r; } public int getPrevious () {return previous; } public int getColdest () {return coldest; } public boolean getFrozen () {return frozen; } }
(All roles in the class: reading - most-recent holder | previous - follower | coldest - most-wanted holder | frozen - one-way flag | r - fixed value)
Examples of use:
closest := 1; for i := 2 to 100 do if (a[i] - target) < (a[closest] - target) then closest := i
Notes:
Technical definition:
Properties:
|
One-way flag
A two-valued data entity that cannot get its initial value once its value has been changed. |
Procedural example:
program dateValidation; var day, month, year: integer; error: Boolean; begin write('Enter day: '); readln(day); error := (day < 1) or (day > 31); write('Enter month: '); readln(month); error := error or (month < 1) or (month > 12); write('Enter year: '); readln(year); case month of 1,3,5,7,8,10,12: (* ok *) ; 4,6,9,11: error := error or (day > 30); 2: if (year mod 400 = 0) or ((year mod 4 = 0) and (year mod 100 <> 0)) then error := error or (day > 29) else error := error or (day > 28) end; if error then writeln('Date incorrect.') else writeln('Date correct.') end.
(All roles in the program: day - fixed value | month - fixed value | year - fixed value | error - one-way flag)
Object-oriented example:
public class Thermometer { private int reading=-999, previous=-999, coldest=-999; private boolean frozen=false; public Thermometer () { } public int getReading () { return reading; } public void setReading (int r) { if (r < coldest) coldest = r; if (r < 0) frozen = true; previous = reading; reading = r; } public int getPrevious () {return previous; } public int getColdest () {return coldest; } public boolean getFrozen () {return frozen; } }
(All roles in the class: reading - most-recent holder | previous - follower | coldest - most-wanted holder | frozen - one-way flag | r - fixed value)
Examples of use:
Notes:
Technical definition:
Properties:
|
Transformation
A data entity that gets its new value always with the same calculation from value(s) of other data entity(s). |
Procedural example:
program sine; const DegToRad = 2.0 * 3.14159 / 360.0; var i: integer; rad: real; spaces: integer; begin for i := 0 to 36 do begin rad := i * 10.0 * DegToRad; spaces := trunc( (sin(rad)+1.0) * 40 ); writeln(' ' : spaces, '*') end end.
(All roles in the program: i - stepper | rad - transformation | spaces - transformation)
Object-oriented example:
public class ReversableString { private String string; public ReversableString (String s) { string = s; } public String get() { return string; } public void reverse() { char[] chararray = string.toCharArray(); int length = string.length(); char tmp; for (int i = 0; i<length/2; i++) { tmp = chararray[i]; chararray[i] = chararray[length-i-1]; chararray[length-i-1] = tmp; } string = new String(chararray); } }
(All roles in the class: string - organizer | s - fixed value | chararray - organizer | length - transformation | tmp - temporary | i - stepper)
Examples of use:
Notes:
Technical definition:
Properties:
|
Follower
A data entity that gets its values by following another data entity. |
Procedural example:
program distance; var month, current, previous, largestDifference: integer; begin write('Enter 1. value: '); readln(previous); write('Enter 2. value: '); readln(current); largestDifference := current - previous; for month := 3 to 12 do begin previous := current; write('Enter ', month, '. value: '); readln(current); if current - previous > largestDifference then largestDifference := current - previous end; writeln('Largest difference was ', largestDifference) end.
(All roles in the program: month - stepper | current - most-recent holder | previous - follower | largestDifference - most-wanted holder)
Object-oriented example:
public class Thermometer { private int reading=-999, previous=-999, coldest=-999; private boolean frozen=false; public Thermometer () { } public int getReading () { return reading; } public void setReading (int r) { if (r < coldest) coldest = r; if (r < 0) frozen = true; previous = reading; reading = r; } public int getPrevious () {return previous; } public int getColdest () {return coldest; } public boolean getFrozen () {return frozen; } }
(All roles in the class: reading - most-recent holder | previous - follower | coldest - most-wanted holder | frozen - one-way flag | r - fixed value)
Examples of use:
Notes:
Technical definition:
Properties:
|
Temporary
A data entity holding some value for a very short time only. |
Procedural example:
program bubbleSort; var i, j, temp: integer; a: array [1..10] of integer; begin for i := 1 to 10 do begin write('Enter number: '); readln(a[i]); end; for i := 1 to 9 do for j := i+1 to 10 do if a[i] > a[j] then begin temp := a[i]; a[i] := a[j]; a[j] := temp end; for i := 1 to 10 do writeln(a[i]) end.
(All roles in the program: i - stepper | j - stepper | temp - temporary | a - organizer)
Object-oriented example:
public class ReversableString { private String string; public ReversableString (String s) { string = s; } public String get() { return string; } public void reverse() { char[] chararray = string.toCharArray(); int length = string.length(); char tmp; for (int i = 0; i<length/2; i++) { tmp = chararray[i]; chararray[i] = chararray[length-i-1]; chararray[length-i-1] = tmp; } string = new String(chararray); } }
(All roles in the class: string - organizer | s - fixed value | chararray - organizer | length - transformation | tmp - temporary | i - stepper)
Examples of use:
Notes:
Technical definition:
Properties:
|
Other
Any other data entity. |
Procedural example:
not provided
Object-oriented example:
not provided
Examples of use:
Notes:
Technical definition:
Properties:
|
Last updated: September 16, 2005