Beispiel #1
0
        //客户要什么样的车
        //实现 给什么样的车 并告诉这个车多少钱
        static void Main(string[] args)
        {
            Console.WriteLine("您想要什么车");
            string  car     = Console.ReadLine();
            GiveCar givecar = GiveCar.GetCar();        //子类赋值给父类
            WhatCar whatCar = givecar.GiveYouCar(car); //抽象类父类

            whatCar.Car();
            GiveMoney givemoney = GiveMoney.GetMoney();     //子类赋值给父类   依赖倒置 面对接口(大的方面)
            Money     money     = givemoney.Givemoney(car); //接口父类

            money.money();
        }
Beispiel #2
0
        public WhatCar GiveYouCar(string str)
        {
            WhatCar whatCar = null;

            switch (str)
            {
            case "保时捷": whatCar = new Porsche(); break;

            case "玛莎拉蒂": whatCar = new Masearti(); break;

            case "兰博基尼": whatCar = new Lamborghini(); break;

            case "劳斯莱斯": whatCar = new RollsRoyce(); break;
            }
            return(whatCar);
        }