property or method?
Posted on 1998-12-17
I don't understand when the property should be used in a class. For example, if a class has a variable
Dim MyValue as integer
public property get GetValue()
GetMyValue = MyValue
However, in this situation, a method declared in the class also can achieve the purpose
public function GetValue() as integer
GetValue = MyValue
Also, for example, a class and 2 variable
Dim X as integer
DIm Y as integer
Public property Get Sum()
sum = X + Y
The property return the sum of 2 valuable. Similar declaring a method also can achive that.
Is it a common practice that property should be used in a class or in a user define control in getting or assign class's variables? Also, in which condition that property should be used instead of the method? What's the actually different between them in the above examples.
Thanks in advance