SLIDE 4 4
I ntroduction to Programming – Lecture 7
10 Chair of Softw are Engineering
Fields reflect attributes of the class
class POSITION feature – Access x: REAL
y: REAL
feature – Element change set_position (xval, yval: REAL) is
- - Set coordinates to (` xval', ` yval').
require x_positive: xval > = 0 y_positive: yval > = 0 do
x : = xval y : = yval
ensure x_set: x = xval y_set: y = yval end end
An attribute Another attribute
Attributes are features of the class
I ntroduction to Programming – Lecture 7
11 Chair of Softw are Engineering
Setting fields (in routines of the class)
class POSITION feature – Access x: REAL
y: REAL
feature – Element change set (xval, yval: REAL) is
- - Set coordinates to (` xval', ` yval').
require x_positive: xval > = 0 y_positive: yval > = 0 do
x : = xval y : = yval
ensure x_set: x = xval y_set: y = yval end end
I ntroduction to Programming – Lecture 7
12 Chair of Softw are Engineering
What you may do
class METRO_STATI ON feature x, y: REAL
- - Coordinates of metro station
size: REAL
- - Size of bounding square
upper_left: POSITI ON
- - Upper-left position of bounding square
adjust_positions is
- - Set positions of bounding square
do upper_left . set (x – size/ 2, y + size/ 2) ... end end Station bounding square size