J
Jon Rea
I hav been looking for the last 2 hours on how to do this without much luck.
Im going to give a simplifed model of the problem i have.
I want a collection class that can holds a series or objects, for arguments
sake, lets make these fruit :
apple
orange
bannana
in my application i have
public abstract class Fruit
{
float m_Weight = 0.0f;
public void setweight(float weight)
}
public class Apple : Fruit
{
}
public class Orange : Fruit
{
}
public class Bannana : Fruit
{
}
What i want to implement is a collection class that can hold a series of
items.
ArrayList theFruit = new ArrayList();
Now i want to open a file
pseudocode :
Openthefile(fruity.txt)
{
foreach line in the file
{
find the correct object type
create that object type
add the data to it
add it to the collection class
}
}
Now the file will contain a list something like this, i.e. a random list of
fruit.
Type, Weight
Bannana 1.03
Apple 2.12
Pear 4.23
Bannana 5.34
Bannana 1.22
Apple 3.33
How do i make the collection class contain objects of the correct type at
runtime ????
Many Thanks for anyones help
Jon Rea
Im going to give a simplifed model of the problem i have.
I want a collection class that can holds a series or objects, for arguments
sake, lets make these fruit :
apple
orange
bannana
in my application i have
public abstract class Fruit
{
float m_Weight = 0.0f;
public void setweight(float weight)
}
public class Apple : Fruit
{
}
public class Orange : Fruit
{
}
public class Bannana : Fruit
{
}
What i want to implement is a collection class that can hold a series of
items.
ArrayList theFruit = new ArrayList();
Now i want to open a file
pseudocode :
Openthefile(fruity.txt)
{
foreach line in the file
{
find the correct object type
create that object type
add the data to it
add it to the collection class
}
}
Now the file will contain a list something like this, i.e. a random list of
fruit.
Type, Weight
Bannana 1.03
Apple 2.12
Pear 4.23
Bannana 5.34
Bannana 1.22
Apple 3.33
How do i make the collection class contain objects of the correct type at
runtime ????
Many Thanks for anyones help
Jon Rea