Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the Singleton pattern #4

Open
briandamaged opened this issue Dec 20, 2010 · 0 comments
Open

Simplify the Singleton pattern #4

briandamaged opened this issue Dec 20, 2010 · 0 comments

Comments

@briandamaged
Copy link
Owner

Every singleton in the code uses the same boilerpoint code:

Dim Something_Singleton__
Public Function Something()
   If IsEmpty(Something_Singleton__) Then
      Set Something_Singleton__ = New Something_Class
      Something_Singleton__.Initialize ...
   End If
   Set Something = Something_Singleton__
End Function

It would be handy if this code could just be generated on the fly. However, VBScript's 2-phase parsing might make this impossible (this was the reason the singleton pattern was developed in the first place). These phases are:

  1. Compile all of the functions that are defined in the script
  2. Execute the body of the script

Unfortunately, we cannot solve the singleton issue by simply generating all of the code in phase 2. We cannot guarantee the order in which files will be executed, so one file may refer to a function in another file that has not been generated/defined yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant