Company Ghost Story 公司鬼故事 12

contents

  1. 1. Java
    1. 1.1. Fancy OOP
    2. 1.2. Shit Cache
    3. 1.3. Shit Cache in Class

Java

Fancy OOP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class MSTAlgorithmEngine {
JButton mApplyButton; // why, ???
JPanel mUI; // why, ???
}
class DiffRecord {
Action mMergeAction; // why, ???
Action mShowAction; // why, ???
}
class Rectangle {
void normalize() {
new NormalizeAction().actionPerformed(new ActionEvent(ActionEvent.PERFORMED));
} // I cannot deal with this shit anymore.
class NormalizeAction extends AbstractAction {
// real implementation for model class
}
}

資料歸資料,算法歸算法,別把 UI 牽扯進來。

Shit Cache

1
2
3
4
5
6
7
8
class Engine {
private static CacheStructure sCache;
public void exec() {
resetCache();
// fill cache;
} // but, when will you clear sCache, sCache = null?
}

快取的污染啊,那些殘存的資料依舊卡在記憶體內,是無法被 GC 回收的。反而,造成下一個運行的更容易出現記憶體不足。

Shit Cache in Class

1
2
3
4
5
6
7
8
9
10
11
class Dbo extends DbObject {
private CacheStructure mCache; // for internal recursion, why this thing is here?
public Object getSomething() {
// init cache
return internalGetSomething(parameters);
} // but, when will you clear cache, cache = null?
private Object internalGetSomething(parameters) {
// ...
}
}

別亂放你的資料結構,這關資料庫物件什麼事?