THE 9 STEPS
9 steps to better software design today
by Jeff Bay
2. One level of indentation per method
2 STEP
class Board {
...
String board() {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++)
buf.append(data[i][j]);
buf.append(“\n”);
}
return buf.toString();
}
}
2 STEP
class Board {
...
String board() {
StringBuffer buf = new StringBuffer();
collectRows(buf);
return buf.toString();
}
void collectRows(StringBuffer buf) {
for (int i = 0; i < 10; i++)
collectRow(buf, i);
}
}
void collectRow(StringBuffer buf, int row) {
for (int i = 0; i < 10; i++)
Buf.append(data[row][i]);
buf.append(“\n”);
}
}
}
3. DON’T USE THE ELSE KEYWORD
3. WRAP ALL PRIMITIVES AND STRINGS
4. FIRST CLASS COLLECTIONS
7. KEEP ALL ENTITIES SMALL
8. NO CLASSES WITH MORE THAN TWO INSTANCE VARIABLES
9. NO GETTERS/SETTERS/PROPERTIES
Artigo
http://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf