5장 형식 맞추기
클린 코드 5장을 요약한 내용 입니다.
Last updated
// Option 1. 분리하지 않은 코드
pacakge fitnesse.wikitext,widgets;
import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String RegEXP = "'''.+?'''";
...
}
public BoldWidget(ParentWidget parent, String text) throws Exception {
super(parent);
...
}
public render( ) throws Exception {
StringBuffer html = new StringBuffer("<b>");
...
}
// Option 2. 행으로 분리된 코드
pacakge fitnesse.wikitext,widgets;
import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String RegEXP = "'''.+?'''";
...
}
public BoldWidget(ParentWidget parent, String text) throws Exception {
super(parent);
...
}
public render( ) throws Exception {
StringBuffer html = new StringBuffer("<b>");
...
}// Option 1. 연관되어 있지만 세로 밀집도가 약한 코드
public class ReporterConfig {
/**
* 리포터 리스너의 클래스 이름
*/
private String m_className;
/**
* 리포터 리스너의 속성
*/
private List<Property> m_properties = new ArrayList<Property>();
...
// Option 2. 연관되어 있는 세로 밀집도가 높은 코드
public class ReporterConfig {
private String m_className;
private List<Property> m_properties = new ArrayList<Property>();
...private static void readPreferences() {
InputStream is = null;
try {
is = new FileInputStream(getPerferencesFile());
setPerferences(new Properties(getPreferences()));
getPreferences().load(is);
} catch (IOException e) {
try {
if (is != null)
is.close();
} catch (IOException e1) {
...
}
}
}Integer age;
for(int i=0; i < 100; i++) {
age = i;
}