Interfaces are a feature of C# that I've never quite been able to see the purpose of. I see them used all the time in professional code, but for the life of me I can't work out the reasoning.
My question here is specifically about interfaces to simulate multiple inheritance. In reading around the subject, I'll often come up on an example like this:
interface IAddition
{
int add(int a, int b);
}
interface ISubtraction
{
int sub(int a, int b);
}
class Calculation : IAddition, ISubtraction
{
public int add(int a, int b)
{
return result1 = a + b;
}
public int sub(int a, int b)
{
return result1 = a - b;
}
}
What I don't understand is - what benefit do the interfaces bring here? It looks to me like you could remove them completely, and the Calculation class would still work exactly the same. What am I missing here?
Any help would be appreciated - I've been looking for something to make interfaces 'click' in my head for quite a while now.
The reason I look for the solution to this is for making games. Multiple inheritance seems to be a good solution for making flexible game objects, but I've haven't quite got a proper grasp of it yet.