Hi Guys,
Say I have a function with just a single parameter. Is it possible to call a particular object based on that param? i.e. I have 2 different classes ClassA and ClassB. If param = 1, I call ClassA.doSomething if param = 2, i call ClassB.doSomething. Note, that both the classes have the same function name but each one does this same taskdifferently and achieves a different result.
The only solution I can think of would use cases or if and else:
Function(iParam)
{
if(iParam == 1)
{
ClassA.doSomething;
}
else if(iParam ==2)
{
ClassB.doSomething;
}
}
Function(iParam)
{
if(iParam == 1)
{
ClassA.doSomething;
}
else if(iParam ==2)
{
ClassB.doSomething;
}
}
To copy to clipboard, switch view to plain text mode
I obviously want to steer away from having 100 if and else statements. The main problem I have with this is the fact that I'll be creating an instance on the heap of only 1 of these classes, and I just need to access an objects function based on which one is loaded on the heap.
Bookmarks