while iter has Next Item item Itemiter next













- Slides: 13
コーディングパターンとは ・ 頻出する定型的なコード片 ・ メソッド呼び出し,制御構造要素の列 while (iter. has. Next()) { Item item = (Item)iter. next(); buf. append(item. to. String()); } コピー & ペースト イディオム の再利用 while (iter. has. Next()) { Item item = (Item)iter. next(); buf. append(item. to. String()); } while (iter. has. Next()) { Data data = (Data)iter. next(); buf. append(process(data)); buf. append(data. to. String()); } 平成 20年度 情報処理学会 関西支部 支部大会 2008/10/24 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 3
コーディングパターン例 イテレータ Collection. iterator() Iterator. has. Next() LOOP Iterator. next() Iterator. has. Next() END-LOOP コーディングパターン ~ イディオム ~ … Iterator it = list. iterator(); while( it. has. Next() ) { Item item = (Item)it. next(); if (item. is. Active()) { item. deactivate(); } } … … for( Iterator it = list. iterator(); it. has. Next(); ) { Item item = (Item)it. next(); if (item. is. Active()) { item. deactivate(); ソースコード } } … インスタンス 平成 20年度 情報処理学会 関西支部 支部大会 2008/10/24 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 5
コーディングパターン例 ~ アプリケーション固有の機能実装 ~ Undo機能の実装 JHot. Draw(Ver. 5. 4 b 1) create. Undo. Activity() set. Undo. Activity() get. Undo. Activity() set. Affected. Figures() コーディングパターン public void reverse. Action(Figure figure) { set. Undo. Activity(create. Undo. Activity()); List l = Collections. Factory. current(). create. List(); l. add(figure); l. add(((Decorator. Figure)figure). peel. Decoration()); get. Undo. Activity(). set. Affected. Figures( new Figure. Enumerator(l)); ((Border. Tool. Undo. Activity)get. Undo. Activity()). replace. Affected. Figures(); } public void execute() { super. execute(); set. Undo. Activity(create. Undo. Activity()); get. Undo. Activity(). set. Affected. Figures(view(). selection()); Figure. Enumeration fe = get. Undo. Activity(). get. Affected. Figures(); … } 平成 20年度 情報処理学会 関西支部 支部大会 インスタンス 2008/10/24 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 6
DEN(DENsity) LOOP a() b() END-LOOP LENpat • パターンインスタンスの密度( DENinst)の平均 コーディングパターン v() LOOP a() b() w() x() END-LOOP y() z() インスタンス DENinst = LENpat / LENinst DENinst = 4 / 6 LENinst – LENpat • コーディングパターンの要素数 – LENinst • インスタンス開始要素から, インスタンス終了要素までの要素数 平成 20年度 情報処理学会 関西支部 支部大会 2008/10/24 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 10
RAD(RADius) • パターンインスタンスのパッケージ間の分散 度合 RAD = 0 RAD = 1 RAD = 2 pkg 0 2 1 pkg ファイルA ファイルC ファイルA ファイルB パターンインスタンス 平成 20年度 情報処理学会 関西支部 支部大会 2008/10/24 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 11
RNR(Ratio of Non-Repeated elements) • コーディングパターン中の非繰り返し要素の割合 x() a() b() y() z() • RNR = 1 – (繰り返し要素数 / 全要素数) = 1 – (4 / 9) =5/9 コーディングパターン 平成 20年度 情報処理学会 関西支部 支部大会 2008/10/24 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 12