I have a list of items implementing an interface. For the question, let's use this example interface:
interface Person
{
void AgeAYear();
}
There are two classes
class NormalPerson : Person
{
int age = 0;
void AgeAYear()
{
age++;
//do some more stuff...
}
}
class ImmortalPerson : Person
{
void AgeAYear()
{
//do nothing...
}
}
For other reasons, I need them both of the list. But for this call, when I loop through my list of Person
s, I may be calling empty functions. Will this have a performance impact? If so, how much? Will the empty function, for all intents and purposes, be optimized out?
NOTE: In the real example, the ImmortalPerson
has other methods that do have code - it is not just an object that does nothing.