60 lines
1.7 KiB
Plaintext
60 lines
1.7 KiB
Plaintext
=== is related to: S4454
|
|
|
|
=== on 4 Mar 2016, 12:09:12 sytze van koningsveld wrote:
|
|
This description is not correct; subclasses are allowed to loosen the contract on parameters, and tightened on return values; see also \https://en.wikipedia.org/wiki/Liskov_substitution_principle. Example :
|
|
|
|
|
|
public class Raspberry extends Fruit {
|
|
|
|
|
|
public void setRipe(Season ripe) { //compliant
|
|
|
|
this.ripe = ripe;
|
|
|
|
}
|
|
|
|
|
|
public @Notnull Integer getProtein() throws MyException { //compliant
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
=== on 4 Mar 2016, 13:47:47 Ann Campbell wrote:
|
|
\[~sytzevk] it's allowable - that's why it compiles. But it may not be the best idea.
|
|
|
|
=== on 4 Mar 2016, 15:12:49 sytze van koningsveld wrote:
|
|
so Liskov's principle is a bad idea ? Can you elaborate a bit on why you think a fundamental property of object orientation is not the best idea ?
|
|
|
|
|
|
|
|
=== on 7 Mar 2016, 10:36:04 Nicolas Peru wrote:
|
|
Hi [~sytzevk],
|
|
|
|
First a word about the formulation of your question :
|
|
|
|
While we love hearing (negative) feedback, please keep a polite voice and avoid passive agressive tone like in your last question. Being right and pointing out errors of others does not allow to be rude (on the contrary). Thanks.
|
|
|
|
|
|
Now for the content of your feedback:
|
|
|
|
If you think about this rule as a rule to detect LSP violations, then indeed, it does not work as it will detect cases that are not LSP violations when you loosen contract on parameters and tighten on return values (false positives).
|
|
|
|
|
|
As a first implementation we did not think about it like this, so I'll update the description and create a ticket to fix this rule.
|
|
|
|
|
|
Thanks!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== on 9 Jan 2018, 16:39:30 Amaury Levé wrote:
|
|
This rule cannot be implemented in C#/VB.Net as these annotations do not exist.
|
|
|