rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

Concrete implementations should be private #2704

Open retailcoder opened 7 years ago

retailcoder commented 7 years ago

By default, the VBE makes interface member implementations (/event handlers) Private, which leaves the member invisible to consumers of the concrete type, but visible to consumers of the interface.

We need an inspection that finds Public interface implementations, with a quick-fix that makes them Private.

The catch is that doing that might break callers if the callers are written against the concrete type, so the inspection's meta description should mention that.

retailcoder commented 7 years ago

The quick-fix should be disabled if the member has direct callers. This makes it a little bit more difficult to implement, but not too much.

Vogel612 commented 7 years ago

On that note: We should flag such direct callers in another inspection. "Explicit call to interface member on concrete class instance" seems like a good idea. The quickfix would then declare the accessed variable As Interface instead of As ConcreteClass (assuming that's possible)...

For instances where both call types are intermingled, we could have another related inspection (but that might be asking too much).

retailcoder commented 7 years ago

@Vogel612 we know which interface(s) the concrete class is implementing, so there could be a quick-fix for changing the declaration to either. e.g. "Declare As ISomething" and "Declare As ISomethingElse", assuming the concrete type implements both ISomething and ISomethingElse.

Hmm.. that feels like R#'s "(thing) can be declared as (interface)"...