Is there any language or language feature where you can re-call the constructor on an instance of a class and is there any reason why you don't want to do this?
//let's say you have this: var person = new PersonModel("John", "Doe"); // is it possible to do this: person.constructor("Jane", "Doe");
I'm writing code and I have a case where I have reusable objects (data objects in collection) and being able to update the object through the constructor parameters would be an easy way to update the data object for me for right now in my specific case. I know I can break the code up if to do the same thing.
I'm creating a Collection View in C# in Xamarin that wraps NSCollectionView (think grid layout in HTML) and I wanted to prepopulate the grid with ten items for the user to see and click on. So these are placeholder items because the Collection View won't be created unless it has data. But the items are like images. They have to be loaded. So I have to have data, even dummy data, to create the view.
So, I created the Data Value Objects or Data Models to create the grid of items. Then when the user clicks on the grid item I can load in an image. So since I already have the data object and simply need to load in content I want to reuse it. It wouldn't mess up the layout or any animations or anything else that creating a new object might.
It would take one line of code if I could reuse the object compared to about 100 lines of code to break out the constructor and other related things like create a new instance with the new information.