RDC00411: Code in a class implemented as an interface
Severity: Warning · Family: RDC (Rubberduck Core analyzers) ·
Raised by: ImplementedInterfaceMemberAnalyzer
A class that another class of the project implements as an interface has code in one of its members.
A class module that writes Implements IShape gives each member of IShape a body of its own
(MS-VBAL §5.2.4.2 Implements Directive).
A call made through a variable declared As IShape runs the body of the object's own class. The code written in IShape runs only on an object created
from IShape itself. A class written to be an interface usually declares its members with no code.
The class is reported once, at the first member that has code: a statement, or a Dim, Static or Const declaration. Comments and line labels are not
code.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
A class that another class implements (Implements IShape), with code in one of its members. |
Public Function Area() As Double: Area = 0: End Function in IShape |
Remove the code, so that each class that implements it gives the member its code. Keep it if objects of IShape itself are created. |
Quick fix
The diagnostic comes with a quick fix, Remove the code from the members of '…'. It removes the lines from the first statement, label or declaration of
each member to the line before its End, and keeps the header, the comments above the first statement and the Attribute lines. This changes what the
code does: an object created from the class itself runs none of the removed code, and its functions and Property Get members return the default value of
their type.
The quick fix is not offered when a statement shares a line with the header or the End of its member, or when the member holds an #If directive.
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca