-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPointlessForwardingMethod.qhelp
More file actions
31 lines (27 loc) · 1.18 KB
/
PointlessForwardingMethod.qhelp
File metadata and controls
31 lines (27 loc) · 1.18 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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
If a class contains two distinct methods of the same name such that:</p>
<ol><li>One method is only ever called from the other method.</li>
<li>The calling method calls only the other method and nothing else.</li></ol>
<p>
Then the first method is no more than a forwarding method for the second and the two methods can
probably be merged.</p>
<p>
There are several
advantages to doing this:
</p>
<ul>
<li>It reduces the cognitive overhead involved in keeping track of the various different overloaded forms of a method.</li>
<li>If both methods are public, it simplifies the API of their containing class, making it more discoverable to other programmers.</li>
<li>It makes it clearer to other programmers that certain methods are called and other methods are not.</li>
</ul>
</overview>
<example>
<p>In this example, the two <code>print</code> methods in <code>Bad</code> can be merged, as one is simply a forwarder for the other. The two classes <code>Better1</code> and <code>Better2</code>
show two alternative ways of merging the methods.</p>
<sample src="PointlessForwardingMethod.java" /></example>
</qhelp>