Home arrow static arrow Java Programming [Archive] - "Extension" of object to specific subclass?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - "Extension" of object to specific subclass?
This topic has 2 replies on 1 page.

Posts:3,369
Registered: 24.10.97
"Extension" of object to specific subclass?  
Jul 22, 2004 3:47 AM



 
Is it possible to somehow "extend" an object so that it is an instance of a specific sublass?

The problem: the superclass does lots of initialisation and checks. The result of one check is what specific processing class should be used. But all of the specific processing classes als extend this superclass (because they use all the results and init values from the super class object). So, instead of creating a new object of the specific subclass, and do all the init, check, processing stuff of the super class again (or offer methods in the same superclass to set the values that are retrieved from the first object but the same class), i'm looking for a way to tell the object: "Hey, now i know what subclass to use. Transform yourself to this sublcass so that i don't need to instantiate a new object and do lots of stuff again."
 

Posts:18,384
Registered: 21.03.00
Re: "Extension" of object to specific subclass?  
Jul 22, 2004 3:51 AM (reply 1 of 2)



 
Hi,

No, that's not possible.

/Kaj
 

Posts:24,036
Registered: 2/3/03
Re: "Extension" of object to specific subclass?  
Jul 22, 2004 5:16 AM (reply 2 of 2)



 
Look at the Factory Method design pattern.
 
This topic has 2 replies on 1 page.