Skip to content

Instantly share code, notes, and snippets.

@Khanashima
Created May 3, 2014 13:06
Show Gist options
  • Save Khanashima/11497565 to your computer and use it in GitHub Desktop.
Save Khanashima/11497565 to your computer and use it in GitHub Desktop.
オブジェクト指向に近づく9つのルール (ThoughtWorks アンソロジーより) ref: http://qiita.com/kiimiiis/items/dab7ebbcab640b4f2aa0
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();
}
}
class Board {
//1つのメソッドにつきインデントは1段階までにする
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");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment