Information verstecken

schlecht:class C { int foo; },

besser:

class C {  private int foo;
  int getFoo () { return this.foo; }
  void setFoo (int foo) { this.foo = foo; }
}
(Eclipse: source: generate getter/setter, refactor: encapsulate field)

...am besten

class C { private final int foo;
   C (int foo) { this.foo = foo; }
}
(Eclipse: generate constructor ...)



Johannes Waldmann 2008-01-23