0

Should I pass the instance of my class between forms or create a new instance?

I have a custom class I'm using on 3 separate forms. Should I create a single instance and pass it though or create a new instance for each form?

13th Dec 2016, 3:06 AM
miketech
miketech - avatar
1 Answer
+ 1
It depends if all forms should operate on the same instance (changes by one form will reflect in the other forms) or not (changes by one form is restricted to the instance held by that form). If all forms should operate on the same instance, pass a reference of the object to the other forms. If not, create a copy for each of the other forms. My guess is you want all forms to use the same object, but it depends on your use case.
13th Dec 2016, 7:47 AM
Ettienne Gilbert
Ettienne Gilbert - avatar