Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vbscript static class variables/methods?

Is there a way to have one variable per class in vbscript?

If not what is the best way to emulate it? Prefixing a global variable declared next to the class?

Also is there a way to declare static/class methods(for a static constructor) or am I force to prefix a function?

like image 608
Roman A. Taycher Avatar asked Oct 06 '22 09:10

Roman A. Taycher


1 Answers

In languages that support class-level/static data or methods you can

  1. associate/bind data or methods explicitly to the set of objects defined by the class. So you can have Customer.Count and Product.Count and a plain Count (or @@Count) in Customer code will access the right number.
  2. use such data or method without having an instance of the class (yet).

VBScript does not support static data or methods. You have to use global data or functions/subs and do the associating in your mind (perhaps with a little help from a naming convention). Accessing these 'static'=global elements without an object is trivial, but - obviously - should be done with care.

You can embed one or more singleton objects or code references (GetRef()) in your objects to bind them closer to the class, but that will increase the size of the instances.

like image 170
Ekkehard.Horner Avatar answered Oct 10 '22 02:10

Ekkehard.Horner