Files
codeql/cpp/ql/src/Metrics/Classes/CNumberOfFields.qhelp
2018-08-02 17:53:23 +01:00

54 lines
1.1 KiB
XML

<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This metric measures the number of fields in classes below this
location in the tree. At a class level, it just measures the number of
fields in the class itself.
</p>
<p>
There are at least a couple of reasons why a class may have too many fields:
</p>
<ul>
<li>The class in general may be too big / have too many responsibilities.</li>
<li>Several of the fields may be part of the same abstraction.</li>
</ul>
</overview>
<recommendation>
<p>
The best resolution depends on the underlying reason behind it:
</p>
<ul>
<li>
If the class is too big, it should be split into multiple smaller classes.
</li>
<li>
If several of the fields are part of the same abstraction, they should be
grouped into a separate class, using the 'Extract Class' refactoring described
in [Fowler].
</li>
</ul>
</recommendation>
<references>
<li>
M. Fowler. <em>Refactoring</em> pp. 65, 122-5. Addison-Wesley, 1999.
</li>
<li>
R. Martin. <a href="https://drive.google.com/file/d/0ByOwmqah_nuGNHEtcU5OekdDMkk/view">The Single Responsibility Principle</a>. Published online.
</li>
</references>
</qhelp>