I am getting output as swim, quack and fly. I don't know how to get output from my derived class Mallard, RubberDuck and DecoyDuck. Am I doing anything wrong while implementing derived class from my base class? Can anyone help me.
{
interface IFlyBehavior
{
void Action1();
}
interface IQuackBehavior:IFlyBehavior
{
void Action2();
}
interface ISwimBehavior:IQuackBehavior
{
void Action3();
}
public class Duck:IQuackBehavior
{
public void Action1()
{
Console.WriteLine("fly");
}
public void Action2()
{
Console.WriteLine("quack");
}
public void Action3()
{
Console.WriteLine("Swim");
}
}
public class Mallard: Duck, IFlyBehavior, IQuackBehavior, ISwimBehavior
{
public void Action1(string fly, string quack, string swim){
Console.WriteLine("This duck can {0}, {1}, and {2}", fly, quack, swim);}
}
public class RubberDuck: Duck, IFlyBehavior, IQuackBehavior, ISwimBehavior
{
public void Action2(string fly, string quack, string swim)
{
Console.WriteLine ("This is rubberduck so it might float on water but cannot {0}, {1} or {2}",fly,quack,swim);
}
}
public class DecoyDuck: Duck, IFlyBehavior, IQuackBehavior, ISwimBehavior
{
public void Action3(string fly, string swim, string quack) {
Console.WriteLine("This duck cannot {0}, but {1}, and may be able to {2}",fly,swim,quack);}
}
class Program
{
static void Main()
{
Duck M = new Mallard();
Duck R = new RubberDuck();
Duck D = new DecoyDuck();
M.Action1();
R.Action2();
D.Action3();
}
}
}