You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>