
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Overriding a parent class' method implementation with an ``++abstract++`` method is a terrible practice for a number of reasons:
|
|
|
|
* it blocks invocation of the original class' method by children of the ``++abstract++`` class.
|
|
* it requires the ``++abstract++`` class' children to re-implement (copy/paste?) the original class' logic.
|
|
* it violates the inherited contract.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public class Parent {
|
|
public int getNumber() {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
public abstract class AbstractChild {
|
|
abstract public int getNumber(); // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this "abstract" method override.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 12 Jun 2015, 15:34:57 Ann Campbell wrote:
|
|
CodePro: Overriding a Non-abstract Method with an Abstract Method
|
|
|
|
=== on 12 Jun 2015, 15:50:29 Ann Campbell wrote:
|
|
\[~nicolas.peru] I'm wondering if I should have rolled this into RSPEC-2177, altho I'm a bit reluctant to roll something that deserves a "dope-slap" tag (this one) into something that's mainly an "oops".
|
|
|
|
WDYT?
|
|
|
|
=== on 15 Jun 2015, 20:21:21 Nicolas Peru wrote:
|
|
This one looks good and intent is fairly different: RSPEC-2177 detects abused overloading whereas this one clearly indicates a bad design. As you point it out, severity is definitely not the same.
|
|
|
|
endif::env-github,rspecator-view[]
|