This is probably very easy, but I'm stumped. I would like to create a general purpose class which will be used multiple times in my program. I want this to be very lightweight and super fast.
For a very simple example in C#:
public class SystemTest
{
public TestMethod(string testString)
{
if(testString == "blue")
{
RunA();
}
else if(testString == "red")
{
RunB();
}
else if(testString == "orange")
{
RunA();
}
else if(testString == "pink")
{
RunB();
}
}
protected void RunA() {}
protected void RunB() {}
}
I want the RunA() and the RunB() to be defined and controlled by the object instancing this class. It will be completely up to the object instancing SystemTest class to figure out whatever RunA() and RunB() will be doing. How do you do this?
I don't want the instance object to always inherit this SystemTest class, and I would like it to run super quickly. The only things I'm thinking of are complex, processor intensive stuff. I know there's an easier way to do this.
Edit: Typically, which runs faster, the delegate or the interface method on the answers below?