You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change abstract class with only abstract members to an interface.
Change abstract class without abstract members to a class with protected constructor. We should do the exact opposite on this point.
Why?
If a class should be inherited by design, it should be marked as such in the class declaration. It's an explicit contract on the class level.
The rule asks to create a random member (constructor) placed somewhere inside the class (hard to find by-definition), with a specific visibility and hope that users will infer what the contract was supposed to be from that.
That is not practical from code usability and maintainability point of view.
Attempt to instantiate abstract class provides clear explanation, that is actionable (find implementing class, or create one)
CS0144 Cannot create an instance of the abstract type or interface 'Sample1'
While attempt to instantiate a class with protected constructor provides generic message that is same for private and protected constructors. Making it unclear if the class just should not be created.
CS0122 'Sample2.Sample2()' is inaccessible due to its protection level
What?
Update S1694 to limit its scope to abstract class -> interface part and remove the abstract class -> protected constructor part.
Make the rule SonarWay.
The text was updated successfully, but these errors were encountered:
S1694 asks to do two things:
Change abstract class with only abstract members to an interface.
Change abstract class without abstract members to a class with protected constructor. We should do the exact opposite on this point.
Why?
If a class should be inherited by design, it should be marked as such in the class declaration. It's an explicit contract on the class level.
The rule asks to create a random member (constructor) placed somewhere inside the class (hard to find by-definition), with a specific visibility and hope that users will infer what the contract was supposed to be from that.
That is not practical from code usability and maintainability point of view.
Attempt to instantiate abstract class provides clear explanation, that is actionable (find implementing class, or create one)
While attempt to instantiate a class with protected constructor provides generic message that is same for private and protected constructors. Making it unclear if the class just should not be created.
What?
Update S1694 to limit its scope to
abstract class -> interface
part and remove theabstract class -> protected constructor part
.Make the rule SonarWay.
The text was updated successfully, but these errors were encountered: