private static void Main() { var mallardDuck = new MallardDuck(); mallardDuck.Display(); mallardDuck.PerformQuack(); mallardDuck.Swim(); mallardDuck.PerformFly(); Console.WriteLine(); var redheadDuck = new RedheadDuck(); redheadDuck.Display(); redheadDuck.PerformQuack(); redheadDuck.Swim(); redheadDuck.PerformFly(); Console.WriteLine(); var rubberDuck = new RubberDuck(); rubberDuck.Display(); rubberDuck.PerformQuack(); rubberDuck.Swim(); rubberDuck.PerformFly(); Console.WriteLine(); var decoyDuck = new DecoyDuck(); decoyDuck.Display(); decoyDuck.Swim(); Console.WriteLine(); Console.Write("Press Enter to exit ..."); Console.ReadLine(); }
public void TestMethod1() { IFlyBehaviour flyBehaviour = new FlyBehaviour(); MallardDuck mallardDuck = new MallardDuck(flyBehaviour); RedheadDuck redheadDuck = new RedheadDuck(flyBehaviour); IFlyBehaviour noFlyBehaviour = new NoFlyBehaviour(); RubberDuck rubberDuck = new RubberDuck(noFlyBehaviour); mallardDuck.Display(); mallardDuck.Fly(); redheadDuck.Display(); redheadDuck.Fly(); rubberDuck.Display(); rubberDuck.Fly(); rubberDuck.ChangeFlyBehaviour(flyBehaviour); rubberDuck.Fly(); redheadDuck.Swim(); mallardDuck.Swim(); rubberDuck.Swim(); }
public void RedheadDuck_Should_Quack_Swim_Fly_Display() { var redheadDuck = new RedheadDuck(); Assert.Equal("quack", redheadDuck.PerformQuack()); Assert.Equal("swim", redheadDuck.Swim()); Assert.Equal("fly", redheadDuck.PerformFly()); Assert.Equal("looks like a redhead", redheadDuck.Display()); }
public static void Main() { Duck redHeaDuck = new RedheadDuck("RedHead", "Red", new FlyWithRocket()); redHeaDuck.Display(); redHeaDuck.MakeItFly(); Duck toyDuck = new ToyDuck("Toy", "Blue", new NoFly()); toyDuck.Display(); toyDuck.MakeItFly(); }
static void Main(string[] args) { Duck duckMallard = new MallardDuck("José"); Duck duckRedhead = new RedheadDuck("Jaum"); Duck rubberDuck = new RubberDuck("Pedro"); duckMallard.Display(); duckMallard.Quack(); duckMallard.Swin(); duckMallard.Fly(); duckRedhead.Display(); duckRedhead.Quack(); duckRedhead.Swin(); duckRedhead.Fly(); rubberDuck.Display(); rubberDuck.Quack(); rubberDuck.Swin(); rubberDuck.Fly(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { DbInitializer.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } FlyWithWings fly = new FlyWithWings(); FlyNoWay noFly = new FlyNoWay(); MallardDuck md = new MallardDuck(fly); RedheadDuck red = new RedheadDuck(fly); RubberDuck rubberDuck = new RubberDuck(noFly); md.Display(); md.Fly(); red.Display(); red.Fly(); rubberDuck.Display(); rubberDuck.Fly(); host.Run(); }
static void Main(string[] args) { Console.WriteLine("##### 例子1 #####"); // 无折扣. DiscountContext c1 = new DiscountContext(new NoDiscountStrategy()); // 每本1元. DiscountContext c2 = new DiscountContext(new FlatRateStrategy() { OneCopyDiscount = 1 }); // 总金额 10% DiscountContext c3 = new DiscountContext(new PercentageStrategy() { Percent = 0.1M }); Console.WriteLine(c1.GetBookDiscount(100, 10)); Console.WriteLine(c2.GetBookDiscount(100, 10)); Console.WriteLine(c3.GetBookDiscount(100, 10)); Console.WriteLine("##### 例子2 #####"); MallardDuck mallardDuck = new MallardDuck(); RedheadDuck redheadDuck = new RedheadDuck(); RubberDuck rubberDuck = new RubberDuck(); Console.WriteLine(mallardDuck.Display() + " # " + mallardDuck.PerformFly().ToString() + " # " + mallardDuck.PerformQuack().ToString()); Console.WriteLine(redheadDuck.Display() + " # " + redheadDuck.PerformFly().ToString() + " # " + redheadDuck.PerformQuack().ToString()); Console.WriteLine(rubberDuck.Display() + " # " + rubberDuck.PerformFly().ToString() + " # " + rubberDuck.PerformQuack().ToString()); Console.ReadLine(); }