I have the following hierarchy: Party is a base class, extended by Person and Corporation.
I need to change the object class of an entity at some point of its life, and I don't know what's the best way to do this.
I'm modeling the financial world, so I have that a Party can own shares of a Corporation, while only Corporation can have shareholders. Something like this:
I build the objects reading data from a source, and it can happen that at first I know only the name of a party, but I don't know wheter it is a Person or a Corporation.
But I need to create an object, so I create a generic Party. After that, it may happen that I come to know more infos, such that my Party was a Corporation. So, I need to change the class that represents that entity from Party to Corporation.
Until now, my solution was to build a new object, copying the old data into it.
But I'm not satisfied with it, and I'm wondering what's the best way, pattern or whatever else, to implement what I'd like to achieve.
I thought to the State Pattern, but I think it is best suited for other situations.