I have a problem which i’ve been googling but can’t find the answer to.
Say if you have a class called Account which inherits from a class called AccountInquiry.
If you have an instance of AccountInquiry, can you convert this into an instance of Account without effectively copying it. If not what is the best way to manage this.
Basically a bit of background, when someone fills in a basic Name/Email form on our website is creates an account inquiry, once they’ve done this they are presented with a 2nd form. If this 2nd form gets fills in the account inquiry is converted into an account.
Many thanks
Sam
It doesn’t sound like an
Accountreally is anAccountInquiry. It sounds much more like these should be two entirely separate classes, even if they have some of the same properties.Be careful before you use inheritance – consider whether it’s really appropriate or not.
In this case your
AccountInquirysounds like it’s effectively search criteria for a realAccount– so you should probably have some service class which is able to perform the query, with a method something like:Or possibly just a return type of
Accountif only a single account should be matched. There’s no “conversion” going on here – you’d just be using the properties of one object to find another.(I suspect it should really be enquiry rather than inquiry by the way, but that’s an aside.)