0
votes

I have a script with a bunch of Subs & Functions that make use of the FileSystemObject, and currently I have a local objFileSystem variable in each procedure. My initial thought was to make the procedures decoupled and reusable, but now I am wondering if I am better off with a single global scope objFileSystem?

  1. I understand this wouldn't be a true Singleton (being VBScript), it is just the question of a single shared object vs multiple dedicated objects, which is like a Singleton.

  2. I have recursion in a couple of places, and I am curious if that changes the best practice at all?

  3. I have a similar condition with a Registry object, and I wonder if the best practice is the same, or do these two behave differently?

  4. I am not (overly) concerned with performance nor memory management, but I would like to understand the Why of any best practice.

1

1 Answers

0
votes

If you actually do re-use functions/procedures elsewhere and aim for strict encapsulation: stick with local instantiation of those objects. Otherwise use singleton instances. This applies to the FileSystemObject and probably to the "registry object" as well (assuming you mean a WMI object here).