public interface ITalk
{
string Shout();
}
public class Dog : ITalk
{
public string Shout()
{
return "Woof, woof woof woof woof";
}
}
public class Cat : ITalk
{
public string Shout()
{
return "Mew Mew Mew";
}
}
public class Parrot : ITalk
{
public string Shout()
{
return "Sqwark! Sqwark! Sqwark!";
}
}
public class Program
{
static void Main(string[] args)
{
// Writes Woof, Woof
ITalk pet = new Dog();
Console.WriteLine(pet .Speak());
// Now writes Meow
ITalk pet = new Cat();
Console.WriteLine(pet .Speak());
// Now writes Sqwark etc
ITalk pet = new Parrot();
Console.WriteLine(pet .Speak());
}
}