What
Code Quality inspection flagging Public members that are event handlers or interface implementations.
Why
Making these members public puts them on the class' default interface, which means underscored members appear in the list of members of the containing class module when an object variable is declared with the class' default interface (i.e. the class name). Instead of being invoked directly, a dedicated (not underscored) public member on the class' default interface should be added; the implementation can be moved to the new public member and invoked from the private interface implementation.
Example
This code should trigger the inspection:
Public Sub Worksheet_BeforeSave(Cancel As Boolean)
'...do stuff...
End Sub
QuickFixes
Should Rubberduck offer one or more quickfix(es) for this inspection? Describe them here (note: all inspections allow for IgnoreOnceQuickFix, unless explicitly specified):
Move implementation to Public method
Kind of an "extract method lite, where we just grab the whole entire method body and mirror the signature:
Example code, after quickfix is applied:
Public Sub DoStuff(Cancel As Boolean)
'...do stuff...
End Sub
Private Sub Worksheet_BeforeSave(Cancel As Boolean)
DoStuff Cancel
End Sub
Resources
Each inspection needs a number of resource strings - please provide a suggestion here:
InspectionInfo: the default interface of a class module should not expose the implementation of other interfaces; event handler procedures should be Private.
InspectionResults: Member '{0}' should be Private.
The quickfix will be really easy once we have implemented extract method; it just needs to make the method private and then use the refactoring action.
What Code Quality inspection flagging
Public
members that are event handlers or interface implementations.Why Making these members public puts them on the class' default interface, which means underscored members appear in the list of members of the containing class module when an object variable is declared with the class' default interface (i.e. the class name). Instead of being invoked directly, a dedicated (not underscored) public member on the class' default interface should be added; the implementation can be moved to the new public member and invoked from the private interface implementation.
Example This code should trigger the inspection:
QuickFixes Should Rubberduck offer one or more quickfix(es) for this inspection? Describe them here (note: all inspections allow for
IgnoreOnceQuickFix
, unless explicitly specified):Move implementation to Public method
Kind of an "extract method lite, where we just grab the whole entire method body and mirror the signature:
Example code, after quickfix is applied:
Resources Each inspection needs a number of resource strings - please provide a suggestion here: