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
This should be a new rule, not an improvement to an existing rule.
This rule would be generally useful, not specific to my code or setup.
Suggested rule title
Interface methods should be public
Rule description
When implementing a method for an interface, Delphi doesn't require that the method be as visible as the interface would suggest.
The following code compiles
type
I = interfaceprocedureFoo;
end;
T = class(TInterfacedObject, I)
privateprocedureFoo;
end;
procedureT.Foo; beginend;
This is an issue because one might look at private procedure Foo and assume that the method can not be accessed from outside the declaring file. However, the method is accessible via the interface:
var
tobj: T;
begin
tobj.Foo; // doesn't compile (outside of the file `T` is declared in)
(tobj as I).Foo; // no issuesend;
This rule would require that all interface methods are implemented with the visibility of public or published, and raise an issue whenever the visibility is lower.
Rationale
Most developers will read the visibility of a method and assume that alone determines how accessible it is. This escape-hatch for interface methods is entirely unexpected and subverts the entire point of access control.
The text was updated successfully, but these errors were encountered:
I can't imagine a good use-case for this type of visibility mismatch between interface and implementing class.
This would probably be a good Sonar Way rule.
Prerequisites
Suggested rule title
Interface methods should be public
Rule description
When implementing a method for an interface, Delphi doesn't require that the method be as visible as the interface would suggest.
The following code compiles
This is an issue because one might look at
private procedure Foo
and assume that the method can not be accessed from outside the declaring file. However, the method is accessible via the interface:This rule would require that all interface methods are implemented with the visibility of
public
orpublished
, and raise an issue whenever the visibility is lower.Rationale
Most developers will read the visibility of a method and assume that alone determines how accessible it is. This escape-hatch for interface methods is entirely unexpected and subverts the entire point of access control.
The text was updated successfully, but these errors were encountered: