Description
Standard Modules and Classes with PredeclaredId = True
behave in a similar manner (i.e., global namespace, no assembly required). However, there are more software design options and opportunities if a Standard Module's code is implemented as a PredeclaredId
Class (Interfaces, Events, etc). Moreover, once a Standard Module's code is relocated to a PredeclaredId
Class, the path-of-resistance to other OO opportunities is likely reduced.
(AFAIK) The only conditions where a PredeclaredId
Class cannot directly replace a Standard Module and its references is when the Standard Module declares:
- Entry-point macros or,
Public
User Defined Type declarations.Public
Constants
When none of the above conditions exist in a Standard Module, I often find myself wishing it was a PredeclaredId
Class (YMMV). This refactoring would simplify that conversion process and so, would facilitate the refactoring of legacy projects that are primarily composed of Standard Modules.
The refactoring process would probably be something like:
- Create a new target Class Module with
PredeclaredId = True
- Replicate the contents of the source Standard Module in the target Class Module, replicate
Public
constant declarations asPublic
read-only properties of the same name. - Module qualify all Standard Module external references with the name of the new
PredeclaredId
Class name - Remove the source Standard Module Or...
4a. If the Standard Module declares public UDTs or contains procedures that could be entry points, then retain the Standard Module with all public UDT declarations, and forward all public parameter-less subroutines calls to thePredeclaredId
Class.
Step 4 is where most of the work is. Steps 1-3 largely exist in one form or another.
This refactoring would probably become unnecessary once #892 is implemented.