mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-27 17:15:38 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
26 lines
1.1 KiB
HTML
26 lines
1.1 KiB
HTML
<html>
|
|
<body>
|
|
Reports <a href="https://en.wikipedia.org/wiki/Law_of_Demeter">Law of Demeter</a> violations.
|
|
<p>
|
|
The Law of Demeter is not really a law, but specifies a style guideline: never call a method on an object received from another call.
|
|
The code that follows this guideline is easier to maintain, adapt, and refactor, has less coupling between methods, less duplication,
|
|
and better information hiding. On the other hand, you may need to write many wrapper methods to meet this guideline.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
boolean pay(Customer c, Invoice invoice) {
|
|
int dollars = c.getWallet().contents; // violation
|
|
if (dollars >= invoice.getAmount()) {
|
|
Wallet w = c.getWallet();
|
|
w.subtract(invoice.getAmount()); // violation
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
</code></pre>
|
|
The above example might be better implemented as a method <code>payInvoice(Invoice invoice)</code> in <code>Customer</code>.
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the <b>Ignore calls to library methods and access to library fields</b> option to ignore Law of Demeter violations
|
|
that can't be fixed without changing a library.
|
|
</body>
|
|
</html> |