Help with using Objects that are created on-the-fly.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Scott_Collier
Posted On:   Thursday, December 20, 2001 02:10 PM

Maybe I do not have my mind wrapped around this thing right. I could use some help please. I read in a file that lists the objects I need and can create the objects. Now how can I use those objects to access their methods and stuff? Here's the setup using psuedo and real code: public static void main(String[] args){ /** * Read in a file that lists the objects * I need. For example, SubThing1, * SubThing2, SubThing3, etc ... */ while reading in file{ String name = name of object; try{ Object object = null; Class classDef = Class.forName("com.symphonyinc." + name); object = classDef.newInstance()   More>>

Maybe I do not have my mind wrapped around this thing right. I could use some help please.


I read in a file that lists the objects I need and can create the objects. Now how can I use those objects to access their methods and stuff?


Here's the setup using psuedo and real code:


			
public static void main(String[] args){
/**
* Read in a file that lists the objects
* I need. For example, SubThing1,
* SubThing2, SubThing3, etc ...
*/
while reading in file{
String name = name of object;
try{
Object object = null;
Class classDef = Class.forName("com.symphonyinc." + name);
object = classDef.newInstance();
}catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
}catch(IllegalAccessException iae){
iae.printStackTrace();
}catch(InstantiationException ie){
ie.printStackTrace();
}
}
}


			
public Class Thing{
public Thing(){ initialize stuff }
various methods here
}


			
public Class SubThing1 extends Thing{
public SubThing(){ initialize stuff }
various stuff for this subclass
}

			
public Class SubThing2 extends Thing{
public SubThing(){ initilize stuff }
various stuff for this subclass
}
   <<Less
About | Sitemap | Contact