M2. 与えられたメソッドの循環的複雑度(サイクロマチック複雑度; Cyclomatic complexity)を計測せよ.
- T.J. McCabe: "A Complexity Measure". IEEE Trans. Softw. Eng. SE-2(4) 308-320, 1976. DOI:10.1109/TSE.1976.233837
WMC はクラスに所属するメソッドの複雑さ重みの和として計算される. メソッドの複雑さ重みには循環的複雑度を用いよ.
- S.R. Chidamber , C.F. Kemerer: "A Metrics Suite for Object Oriented Design". IEEE Trans. Softw. Eng. 20(6) 476-493, 1994. DOI:10.1109/32.295895
- Object-Oriented Metrics in Practiceによる定義: "The sum of the statical complexity of all methods of a class. The CYCLO metric is used to quantify the method’s complexity"
ATFDは,対象クラスから(アクセサメソッドによる間接アクセスも含めて)アクセスしている外部クラスのフィールド数を表す.
- Object-Oriented Metrics in Practiceによる定義: "The number of attributes from unrelated classes that are accessed directly or by invoking accessor methods"
TCCは凝集度のメトリクスのひとつで,対象クラス内のすべてのメソッド対のうち,同クラスの特定のフィールドに共通してアクセスするものの割合を表す.
- Object-Oriented Metrics in Practiceによる定義: "The relative number of method pairs of a class that access in common at least one attribute of the measured class"
Object-Oriented Metrics in Practiceによるメトリクスベースの判定戦略によれば,下記を条件をすべて満たすクラスをGod Classとみなす.
ATFD > FEW
(= 5) (Class uses directly more than a few attributes of other classes)WMC >= VERY HIGH
(= 47) [% (Functional complexity of the class is very high)TCC < 1/3
(Class cohesion is low)
閾値にはFEW = 5
, VERY HIGH = 47
を用いよ.
静的解析ツールPMDによる検出も試み,結果を比較せよ.