Exemple #1
0
        public Form1()
        {
            InitializeComponent();
            Duck mallard = new MallardDuck();


            mallard.PerformFly();
            //textBox1.Text = mallard.PerformQuack();
            textBox1.AppendText(Convert.ToString(mallard.PerformQuack()).ToString());
        }
Exemple #2
0
        public static void UseStrategyPattern(IView view)
        {
            //the parts that vary
            IFlyBehavior   mallardFlyBehavior = new FlyWithWings();
            IQuackBehavior mallardQuack       = new MallardQuack();

            Duck mallard = new MallardDuck(mallardFlyBehavior, mallardQuack, view);

            MiniDuckSimulator duckSim = new MiniDuckSimulator(mallard);

            duckSim.Run();
        }
        static void Main(string[] args)
        {
            Duck.Duck mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();

            Duck.Duck model = new ModelDuck();
            model.PerformQuack();
            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            // The strategy pattern defines a family of algorithms,
            // encapsulates each one, and makes them interchangeable.
            // Strategy lets the algorithm vary independently from
            // clients that use it.

            Duck mallard = new MallardDuck();

            mallard.performQuack();
            mallard.performFly();

            Duck model = new ModelDuck();

            model.performFly();

            model.setFlyBehavior(new FlyRocketPowered());

            model.performFly();

            Console.Read();
        }
Exemple #5
0
        public void Mallard_Duck_Test()
        {
            MallardDuck mallard = new MallardDuck();

            Assert.Equal("looks like a Mallard", mallard.Display());
        }