-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTNumberOfFields.qhelp
More file actions
57 lines (42 loc) · 1.15 KB
/
TNumberOfFields.qhelp
File metadata and controls
57 lines (42 loc) · 1.15 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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
A class that contains a high number of fields may indicate the following problems:
</p>
<ul>
<li>The class may be too big or have too many responsibilities.</li>
<li>Several of the fields may be part of the same abstraction.</li>
</ul>
</overview>
<recommendation>
<p>
The solution depends on the reason for the high number of fields:
</p>
<ul>
<li>
If the class is too big, you should split it into multiple smaller classes.
</li>
<li>
If several of the fields are part of the same abstraction, you should
group them into a separate class, using the 'Extract Class' refactoring described
in [Fowler].
</li>
</ul>
</recommendation>
<example>
<p>In the following example, class <code>Person</code> contains a number of fields.</p>
<sample src="TNumberOfFields.java" />
<p>
This can be refactored by grouping fields that are part of the same abstraction into new classes
<code>Name</code> and <code>Address</code>.</p>
<sample src="TNumberOfFieldsGood.java" />
</example>
<references>
<li>
M. Fowler, <em>Refactoring</em>. Addison-Wesley, 1999.
</li>
</references>
</qhelp>