-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDubiousTypeTestOfThis.qhelp
More file actions
30 lines (25 loc) · 1.02 KB
/
DubiousTypeTestOfThis.qhelp
File metadata and controls
30 lines (25 loc) · 1.02 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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
Testing whether <code>this</code> is an instance of a derived type creates a dependency cycle.
Derived types already depend on their parent type and the cast creates a dependency in the other direction.
</p>
<p>Dependency cycles should be avoided as they make code both difficult to read and difficult to test.
In addition, a type should not know about its specific descendants, even though it may impose some
constraints on them as a group (for example, the need for every derived type to implement a method
with a specific signature).</p>
</overview>
<recommendation>
<p>
The base and derived types should be redesigned so that there is no need for the base type to depend
on the types deriving from it.</p>
</recommendation>
<example>
<p>In this example, <code>BadBase</code> introduces a dependency cycle with <code>Derived</code> by
testing the type of <code>this</code>.</p>
<sample src="DubiousTypeTestOfThis.java" />
</example>
</qhelp>