SE450: State: Initial code [20/24] Previous pageContentsNext page

Discuss intrinsic/extrinsic state and field/parameter refactorings.

file:I.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package state.one;

interface I {
  public int f();
  public int g();
  public void changeDirection();
}

class C implements I {
  private boolean state;
  private int i;
  private int j;
  public int f() {
    if (state)
      i += 26;
    else
      i -= 32;
    return i;
  }
  public int g() {
    if (state)
      j += 42;
    else
      j -= 27;
    return j;
  }
  public void changeDirection() {
    state = !state;
  }
}

Previous pageContentsNext page