public override Ship makeShip(string type)
        {
            Ship rockship = null;

            if (type == "ROCK")
            {
                ShipFactory factory = new ShipFactory();
                rockship        = factory.makeShip("R");
                rockship.Speed += ((RocketShip)rockship).GetFirePower();
            }
            //... alte tipuri de racheta
            return(rockship);
        }
示例#2
0
        static void Main(string[] args)
        {
            //Change this value to mimic the behaviour of the corresponding pattern.
            int designPat = 3;

            switch (designPat)
            {
            case 1:
                Console.WriteLine("Singleton Pattern");
                Singleton.Singleton.InstanceVar.Foo();
                Singleton.Singleton.InstanceVar.Foo();
                break;

            case 2:
                Console.WriteLine("Iterator Pattern");
                Person[] pArr = new Person[3]
                {
                    new Person("John", "Doe"),
                    new Person("Will", "Smith"),
                    new Person("Wild", "Cats"),
                };
                People pList = new People(pArr);
                foreach (Person p in pList)
                {
                    Console.WriteLine("{0} {1}", p.FName, p.lName);
                }
                break;

            case 3:
                Console.WriteLine("Factory Pattern");
                //val = 1 for rocket ship and 2 for space ship
                int         val        = 2;
                ShipFactory factoryObj = new ShipFactory();
                Ship        shipType   = null;
                //Create ship object
                shipType = factoryObj.MakeShip(val);
                //To display the type of ship and it's speed
                shipType.ShipStatus();
                break;

            default:
                break;
            }

            Console.ReadKey();
        }
示例#3
0
        public override Ship makeShip(string type)
        {
            Ship ufoship = null;

            if (type == "UFO")
            {
                ShipFactory factory = new ShipFactory();

                ufoship      = factory.makeShip("U");
                ufoship.Name = "UFO new Ship";
            }
            if (type == "BIG UFO")
            {
                ShipFactory factory = new ShipFactory();

                ufoship      = factory.makeShip("B");
                ufoship.Name = "UFO Boss Ship";
            }


            return(ufoship);
        }