-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTSpecialisationIndex.qhelp
More file actions
67 lines (51 loc) · 1.94 KB
/
TSpecialisationIndex.qhelp
File metadata and controls
67 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
Specialization index is the extent to which a subclass overrides the
behavior of its ancestor classes. It is computed as follows:</p>
<ol>
<li>Determine the number of overridden methods in the subclass (not counting overrides of
abstract methods).</li>
<li>Multiply this number by the subclass's depth in the inheritance hierarchy.</li>
<li>Divide the result by the subclass's total number of methods.</li>
</ol>
<p>
If a class overrides many of the methods of its ancestor classes, it
indicates that the abstractions in the ancestor classes should be reviewed.
This is particularly true for subclasses that are lower down in the
inheritance hierarchy. In general, subclasses should <em>add</em> behavior to their
superclasses, rather than <em>redefining</em> the behavior that is already there.
</p>
</overview>
<recommendation>
<p>
The most common reason that classes have a high specialization index is that
multiple subclasses specialize a common base class in the same
way. In this case, the relevant method(s) should be pulled up into the base
class (see the 'Pull Up Method' refactoring in [Fowler]).</p>
</recommendation>
<example>
<p> In the following example, duplicating <code>getName</code> in each of the subclasses
is unnecessary.
</p>
<sample src="TSpecialisationIndex.java" />
<p>
To decrease the specialization index of the subclasses, pull up <code>getName</code> into the base class.
</p>
<sample src="TSpecialisationIndexGood.java" />
</example>
<references>
<li>
M. Fowler, <em>Refactoring</em>, pp. 260-3. Addison-Wesley, 1999.
</li>
<li>
M. Lorenz and J. Kidd, <em>Object-oriented Software Metrics</em>. Prentice Hall, 1994.
</li>
<li>
O. de Moor et al, <em>Keynote Address: .QL for Source Code Analysis</em>. Proceedings of the 7th IEEE International Working Conference on Source Code Analysis and Manipulation, 2007.
</li>
</references>
</qhelp>