Hi, I'm using Object Oriented Programming and some of the classes have a lot of instances. I'm using a touch screen and when making adjustments so it needs to know which instance of the class to call so the proper schedule (in this case) is called.
For classes with say 10 instances, I use a switch case using an ID so it can find the correct instance to change. For example.
switch (ID)
{
case 1: Sch1.changeHour(0); Sch1.printHour(298, 161); break;
case 2: Sch2.changeHour(0); Sch2.printHour(298, 161); break;
case 3: Sch3.changeHour(0); Sch3.printHour(298, 161); break;
case 4: Sch4.changeHour(0); Sch4.printHour(298, 161); break;
case 5: Sch5.changeHour(0); Sch5.printHour(298, 161); break;
}
This works well but now I have a class with 80 instances and will grow to 100 so I'm wondering if theres a more efficient way.
I'm wondering if I can update the instance name using a variable somehow?
I tried this, of course it doesn't work but this is what I'm trying to accomplish. Any ideas?
String instanceName;
instanceName = "Sch4";
instanceName.changeHour(0); // this would actually be Sch4.changeHour(0); as the string is set to "Sch4"
instanceName.printHour(298, 161); // this would actually be Sch4.printHour(298, 161); as the string is set to "Sch4"