Example #1
0
        static void Main(string[] args)
        {
            var weapons = new List <IWeapon>()
            {
                new Gun(),
                new MachineGun(),
                new GranadeLauncher(),
                new Knife()
            };



            Character character = null;

            // Livskov principle
            character = new Knight();
            //character = new Troll();

            //Depend on abstractions, not concrete implementations.
            //Interchangeable algorithms.

            foreach (IWeapon weapon in weapons)
            {
                character.Weapon = weapon;

                character.Attack();
            }

            Console.ReadKey();
        }