Skip to content

Convert to Class Refactoring #5919

Open
@BZngr

Description

@BZngr

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:

  1. Entry-point macros or,
  2. Public User Defined Type declarations.
  3. 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:

  1. Create a new target Class Module with PredeclaredId = True
  2. Replicate the contents of the source Standard Module in the target Class Module, replicate Public constant declarations as Public read-only properties of the same name.
  3. Module qualify all Standard Module external references with the name of the new PredeclaredId Class name
  4. 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 the PredeclaredId 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty-02-duckyResolving these involves the internal API, but with relatively easy problems to solve.difficulty-03-duckInvolves more challenging problems and/or developing within and revising the internals APIenhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.good first issueWant to contribute? That's a good place to start!up-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-duckyuser-experienceIssue relates to user experience (workflow, flexibility, customisation)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions