ZiziChou
我們不睡覺當柯南
public class Keyboard {
private String theInputtedKeycharacterOfHardKeyboard;
}
public class Keyboard {
private String theInputtedKeycharacterOfHardKeyboard;
}
public class HardKeyboard extends Keyboard {
private String input;
}
public void update(String[] data) {
showData(data);
writeToFile(data);
}
隱藏性錯誤
if ((hardKeyboardHidden == 0) == false)
if ((hardKeyboardHidden == 0) == false)
if (hardKeyboard.isConnected())
/** 向左上角移動 */
600+
/** 向左下角移動 */
600+
/** 向右上角移動 */
600+
/** 向右下角移動 */
600+
根本之道:縮短 method
// 打開檔案
File file = new File("xxxx");
try {
//讀取檔案
while (true) {
String row = file.readLine();
// 略
}
} catch (Exception e) {
//略
} finally {
try {
//關閉檔案
file.close();
} catch (Exception e) {
//略
}
}
難以閱讀
public void calculateTax() {
tax = (salary - nonTaxBase) * percentage - tail;
}
File file = new File("xxxx");
try {
while (true) {
String row = file.readLine();
}
} catch (Exception e) {
}
public boolean onKeyDown(int keyCode, keyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_ENTER:
break;
case KeyEvent.KEYCODE_SPACE:
break;
case KeyEvent.KEYCODE_LEFT:
break;
case KeyEvent.KEYCODE_RIGHT:
break;
case KeyEvent.KEYCODE_UP:
break;
case KeyEvent.KEYCODE_DOWN:
break;
case KeyEvent.KEYCODE_BUTTON1:
break;
case KeyEvent.KEYCODE_BUTTON2:
break;
case KeyEvent.KEYCODE_BUTTON3:
break;
...
}
return false;
}
public boolean onKeyDown(int keyCode, keyEvent event) {
if (event.isPrintingKey()) {
return appendInput(keyCode);
} else if (event.isArrowKey(keyCode)) {
return moveCursor(keyCode);
} else if (event.isChannelKey(keyCode)) {
return appendInput(convertChannelToNumber(keyCode));
} else if (event.isFunctionalKey(keyCode)) {
return processFunctionalKey(keyCode);
}
return false;
}
public enum State {
CREATED, UPDATED, DELETED
}
public void process(State state) {
switch (state) {
case State.CREATED:
...
break;
case State.UPDATED:
...
break;
case State.DELETED:
...
break;
default:
return 0 ?
return null?
// 怎麼死得都不知道
}
}
public enum State {
CREATED {
public void process() {
...
}
},
UPDATED {
public void process() {
...
}
},
DELETED {
public void process() {
...
}
};
}
public void process(State state) {
state.process();
}
public class keyboard {
private Sound sound;
public void pressUpKey(int level) {
sound.up(level);
}
}
public class keyboard {
private Sound sound;
public void pressUpKey(int level) {
sound.up(level);
}
}
public class ComputerAction {
public Keyboard keyboard;
public Sound sound;
}
public class Keyboard {
private boolean onKeyDown(int keyCode, KeyEvent event) {
// 輸入
}
private void display() {
// 顯示
}
private List<String> convert(String input) {
// 轉換
}
}
public class Warrior {
public void fight(性別) {
if (男) {
// 處理 A 攻擊
} else if (女) {
// 處理 B 攻擊
} else if (不男不女) {
// 處理 C 攻擊
}
...
}
}
public class Warrior {
public void fight() {
FistFactory.create(條件).attack();
}
public interface Attackable {
public void attack();
}
public class LightFist implements Attackable {
public void attack() {
...
}
}
public class SuperFist implements Attackable {
public void attack() {
...
}
}
public class FistFactory {
public static Attackable create(性別) {
if (女) {
return new LightFist();
} else if (男生) {
return new SuperFist();
}
return null;
}
}
public void setupButton() {
LoginButton loginButton = new LoginButton();
loginButton.addActionListener(
new ActionListener() {
public void actionPerformed(Event e) {
showAlert();
}
});
LogoutButton logoutButton = new LogoutButton();
logoutButton.addActionListener(
new ActionListener() {
public void actionPerformed(Event e) {
showAlert();
}
});
}
public class LoginPage implements ActionListener {
public void setupButton() {
LoginButton loginButton = new LoginButton();
loginButton.addActionListener(this);
LogoutButton logoutButton = new LogoutButton();
logoutButton.addActionListener(this);
}
public void actionPerformed(Event e) {
showAlert();
}
}
public class Browse extends Activity {
public void showToast() {
Toast.makeText(this, "Browse", Toast.LENGTH_LONG).show();
}
}
public class Inbox extends Activity {
public void showToast() {
Toast.makeText(this, "Inbox", Toast.LENGTH_LONG).show();
}
}
public class Checkout extends Activity {
public void showToast() {
Toast.makeText(this, "Checkout", Toast.LENGTH_LONG).show();
}
}
{
"result": [
{
"uid": "pollynull",
"created": 1398838793,
"country": {
"code": "TW",
"name": "台灣"
},
"review": {
"rating": 0,
"total": 0
},
"item_fav": [
"11YYvIsT",
"1jaGFTBy"
],
"seller": false,
"store_fav": [
"suebidowa"
],
"nick": "pollynull",
"intro": "",
"avatar_rev": 0,
"reward": {
"points": 3815
},
"friend": {
"requested": [],
"friend": [
"pollychou"
],
"requesting": []
}
}
]
}
for (int i = 0; i < students.size(); i++) {
...
}
for (int i = 0; i < students.size(); i++) {
...
}
for (Student student : students)
public boolean hasMore() {
if(list.size() > 0) {
return true;
}
return false;
}
public boolean hasMore() {
if(list.size() > 0) {
return true;
}
return false;
}
public boolean hasMore() {
return list.size() > 0;
}
if (user.isLogin()) {
return "你好棒";
}
return "你是誰";
}
if (user.isLogin()) {
return "你好棒";
}
return "你是誰";
}
return (user.isLogin())? "你好棒" : "你是誰";
public class Calculator {
public int add(int a, int b) {
return a + b;
}
}
public class Calculator {
public int sub(int a, int b) {
return a - b;
}
}
public Calculator {
public class Parameter {
public int a;
public int b;
}
public class Calculator {
public int add(Calculator.Parameter param) {
return param.a + param.b;
}
}
public class Calculator {
public int add(Calculator.Parameter param) {
return param.a + param.b;
}
}
if (list != null) {
for (int i = 0; i < list.size(); i++) {
...
}
}
if (list != null) {
for (int i = 0; i < list.size(); i++) {
...
}
}
if (list == null) return;
for (int i = 0; i < list.size(); i++) {
...
}
dialogBuilder.setTitle("title").setIcon(icon.jpg).setText("text").setPositiveButton("ok").setNegativeButton("cancel").build();
dialogBuilder.setTitle("title").setIcon(icon.jpg).setText("text").setPositiveButton("ok").setNegativeButton("cancel").build();
dialogBuilder
.setTitle("title")
.setIcon(icon.jpg)
.setText("text")
.setPositiveButton("ok")
.setNegativeButton("cancel")
.build();