I am trying to understand advanced OOP concepts in C#. Lets say I have an interface and class that derived from this interface. Then, why do we need decleare interface as type while creating object or passing arguments to some method?
interface ILetter
{
void Read();
}
class LoveLetter : ILetter
{
public void Read(){
Console.WriteLine("Love Letter Reading");
}
}
class Program
{
static void Main(string[] args)
{
ILetter myLetter = new LoveLetter();
myLetter.Read();
//Output : "Love Letter Reading"
LoveLetter mySecondLetter = new LoveLetter();
mySecondLetter.Read();
//Output : "Love Letter Reading"
}
}