And this scenario:/-----------\ | Company | \-----------/ / \ / \ /-----------\ /-------------------\ | AcmeLtd | | Company::Division | \-----------/ \-------------------/ \ / \ / /-------------\ | AcmeLtd::IT | \-------------/
We have some incoming data that needs to be dealt with by AcmeLtd::IT. All we know at first however, is that it is related to some company. We also have some configuration data stored in the system, and with this we can map the incoming data as far as AcmeLtd. Having got this far however, we can now find out from AcmeLtd what class the data maps onto, and with that knowledge we can process the data.
Now, how to implement this in code? To start with let's have a ground-rule: that all the knowledge and code to do this must lie within the above classes. we must be able to trigger off the entire process with one call from the outside.
Suggestion 1:
Company->new->run \/ (inside Company::run) create new instance of AcmeLtd. use this to a) get name of AcmeLtd subclass that should process the data, and create an instance of this class or b) get an instance of the AcmeLtd subclass that should process the data \/ (inside Company::run) call the processing method of the object instantiated above
Suggestion 2:
Company->new->run \/ (inside Company::run) AcmeLtd->new->run \/ (inside AcmeLtd::run) AcmeLtd::IT->new->run
Suggestion 3:
Company->new->run \/ (inside Company::run) rebless Company object as AcmeLtd, and alter @ISA appropriately \/ (inside same, reblessed object) use newly available methods to get the name of the AcmeLtd subclass that should process the data, then rebless ourselves again in +to this new class and alter @ISA again \/ (inside same, reblessed object) call newly available processing method
So, curious here. Are any of these suggested methods preferred over the others? Are there any reasons (technical or otherwise) not to use any of them? Are there any other techniques that might be preferred? Anything else that might be relevant?
In reply to inheritance and object creation by knew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |