I thought that would make the problem easier to understand...
It's a chemistry problem
elements
Li, Na, K, Rb, Cs, Fr
all implement interface IAlkaliMetal.
Public Void PrepareCombine(IAlkaliMetal elem1, IAlkaliMetal elem2)
{
if(elem1is Li && elem2 is Li)
Combine(((Li)elem1),((Na)elem2);
else if(elem1is Li && elem2 is Na)
Combine(((Li)elem1),((Na)elem2);
else if(elem1is Li && elem2 is K)
Combine(((Li)elem1),((K)elem2);...
}
This is to illustrate what im trying to do, they don't really combine this
way.
Combine method for each possible input types.
Public Void Combine(Li elem1, Li elem2){....}
Public Void Combine(Li elem1, Na elem2){....}
Public Void Combine(Li elem1, K elem2){....}
so again my question is there a way to design this so i so have to use all
those if else if statement and go directly to the corresponding Combine
method
If there are three inputs then there would be 216.
Ideally, it would just know which overload method to go to.
Public Void PrepareCombine(IAlkaliMetal elem1, IAlkaliMetal elem2)
{
Combine(elem1,elem2);
}
Is there a better way to design this?
Tem
Peter Duniho said:
[...]
I have 36 possibilities, if and else if becomes very messy and lots of
room for making errors.
Im not sure how to use the method you mentioned with more than 1
parameter.
It would really help if you could explain what it is exactly you're
doing. Do you literally have 36 different methods that will be called?
It's possible that the problem can be factored down to something that's
simpler. But if all we know about the problem is that you have 36
different possible outcomes, dependent on two different variables, it's
difficult to see how you'd make it simpler than a straight enumeration of
the possibilities.
If we knew more about the problem, it's likely that there's some
characteristic of it that would allow a simpler way to implement it. But
without that information from you, we're stuck.
Pete