-
Persistance Property
Can someone explain the persistance property to me? I understand that VB is not a true OO language like Java, however I am confused about: If I create 2 instances of a class in VB will each instance retain it's properties.
i.e. I have a ball class, the only property is color. I create one instance and set the color to RED and then I create another instance and set the color to BLUE
dim r as new myDLL.MyClass
dim b as new myDLL.MyClass
r.color = "red"
b.color = "blue"
'Will This always print red then blue, or is there a chance that it could print blue then red, or blue and blue, or red and red.
debug.print r.color
debug.print b.color
-
-
In general persistance is maintained two ways:
the App key in the REGISTRY via SaveSetting GetSetting VB functions.
Or thru the use of a Property bag. Property bag is used from inside a class to persist that class. You can save the property information with a key.
In your case you are not talking about persistence:
You're talking about an idea that doesn't apply to COM: the idea that instances should or could share property values with each other, like thru the use of Public variables. The answer is red is always red, blue always blue. And NO, in spite of some code people have produced here, sharing data between instances of classes almost always leads to disaster, because a property that is common and modifiable across instances of a class means that at no time can any instance ever depend on the contents of the property. It can literally be anything.
-
So, what you are saying is that I cannot depend on a property of one instance to not be changed by another instance? Is there any way around this? Because in other OO languages C++/Java each instance of an object is seperate from anyother instance. In Java I can have an Array of like objects and know with certainty that each one will keep its SET properties.
-
In your example the instances would each return the value you assigned to them. Yes each instance of an object stores its own values.
So the debug would look like this:
red
blue