Referencing the object that invoked a method
I want individuals who create an object of MyClass to be able to view all the properties and the property values. Also, it's handy to be able to write out the properties of an object and their values just for debugging purposes. Of course, having written the class definition myself, I know all the properties of the class, but one of the fundamental principles of object oriented programming is encapsulation (restricting access or hiding some of the object's data).
Most OOP languages have a mechanism to reference the object that invokes a method within the invoked method. Many languages use the "this" keyword to allow for an invoked method to reference the invoking object.
If it were possible in VBScript, then it would also be possible to use the "For...each" language construct of to iterate the object and write out all it's properties and values.
Specifally, this would allow me to write a "Print" method that does not require future modification even if the properties of MyClass are changed (i.e. adding properties or remving properties). Such a "Print" method would automatically scale with future property changes to the MyClass.
Here is the class definition VBScript/Psuedo:
Private Sub Class_Initalize()
m_strValue1 = "one"
m_strValue2 = "two"
m_lngValue1 = 1
Public Sub Print()
For Each x in (ref. to the object that invoked this method)
'Code to access object properties and property values
Here is the class implementation VBScript/Psuedo:
Set myObj = New MyClass
myObj.Value1 = "hello world"
Set myObj = Nothing
Here would be the expected output:
m_strValue1 = one
m_strValue2 = two
m_lngValue1 = 1
Notice the "(ref. to the object that invoked the method)" in the class definition... is there a mechanism in VBScript that will allow for this type of reference?
If so, what is it?
Thanks for any help