Ejemplo n.º 1
0
        public RentalRegistration RentVehicle(RentalRequestDto rentalRequestDto)
        {
            Vehicle vehicle;

            switch (rentalRequestDto.VehicleCategory)
            {
            case VehicleCategoryEnum.SmallCar:
                vehicle = new SmallCar(rentalRequestDto.DashboardMileage);
                break;

            case VehicleCategoryEnum.Van:
                vehicle = new Van(rentalRequestDto.DashboardMileage);
                break;

            case VehicleCategoryEnum.MiniBus:
                vehicle = new MiniBus(rentalRequestDto.DashboardMileage);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var customer = new Customer(rentalRequestDto.CustomerBirthday);
            var booking  = new Booking(rentalRequestDto.StartOfRental);

            return(_rentalRegistration.RentVehicle(vehicle, customer, booking));
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SmallCar sm = new SmallCar("Audi");

            sm.Accelerate();
            Console.WriteLine(sm.Speed);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 简单工厂模式,在未来需要可以转化为抽象工厂模式
        /// </summary>
        /// <param name="etype"></param>
        /// <returns></returns>
        public MobileOBJ Build(EntityType etype)
        {
            switch (etype)
            {
            case EntityType.SmallCar:

                SmallCar newCar = new SmallCar();
                newCar.Color = MobileFactory.RandomColor();

                newCar.SpatialGrid = OxyzPointF.Default;


                return(newCar);

            //				case EntityType.Bus:
            //					Bus  newBus = this.bus.Clone() as Bus;
            //					newBus.Color = MobileFactory.GetRandomColor();
            //					return newBus;
            //
            //				case EntityType.Pedastrain:
            ///Pedastrain  newBus = this.p.Clone() as Pedastrain;
            ////newBus.Color = MobileFactory.GetRandomColor();
            //					return new Pedastrain();
            //				case EntityType.LargeTruck:
            //					return new LargeTruck();

            default:
                break;
            }
            throw new ArgumentException("无法创建参数指定的构造型");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 提供一个基本的描绘car的函数,画一个圆形代表car然后用car的颜色填充
 /// </summary>
 public virtual void PaintCar(Rectangle rec, IEntity car)
 {
     if (car.EntityType == EntityType.Mobile)
     {
         SmallCar cm = car as SmallCar;
         _graphic.FillRectangle(new SolidBrush(cm.Color), rec);
     }
 }
Ejemplo n.º 5
0
    public static T GetCar <T>(string carName) where T : ICar
    {
        ICar objCar = default(T);

        if (typeof(T) == typeof(SmallCar))
        {
            objCar = new SmallCar {
                CarName = carName
            };
        }
        else if (typeof(T) == typeof(MediumCar))
        {
            objCar = new MediumCar {
                CarName = carName
            };
        }
        return((T)objCar);
    }
Ejemplo n.º 6
0
        public static SmallCar BuildSmallCar()
        {
            //switch (etype)
            //{
            //    case EntityType.SmallCar:

            SmallCar newCar = new SmallCar();

            newCar.Color       = MobileFactory.RandomColor();
            newCar.SpatialGrid = OxyzPointF.Default;

            return(newCar);

            //    default:
            //        break;
            //}
            //throw new ArgumentException("无法创建参数指定的构造型");
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Car      car      = new Car(4, 20);
            SmallCar smallCar = new SmallCar(4, 20, 20);
            BigCar   bigCar   = new BigCar(8, 40, 3, 500);

            Console.WriteLine(bigCar.Print());
            Shape shape = new Circle(1, 2);

            Console.WriteLine(shape.GetArea());
            BaseClass    baseClass    = new BaseClass();
            BaseClass    ba           = new DerivedClass();
            DerivedClass derivedClass = new DerivedClass();

            baseClass.fn1();
            baseClass.fn2();
            ba.fn1();
            ba.fn2();
            derivedClass.fn1();
            derivedClass.fn2();
            Cat     cat     = new Cat();
            Dog     dog     = new Dog();
            Student student = new Student();

            for (int i = 0; i < 10; i++)
            {
                Stu stu = new Stu();
                stu.stuName   = stu.stunNum = Convert.ToString(i);
                stu.score.cs  = stu.score.eng = stu.score.math = i;
                stu.score.avg = (stu.score.cs + stu.score.eng + stu.score.math) / 3;
                student.enqueue(stu);
            }
            student.Print();
            Stacks stacks = new Stacks();

            for (int i = 0; i < 10; i++)
            {
                Book book = new Book();
                book.author = book.bookName = book.publish = Convert.ToString(i);
                book.price  = i;
                stacks.Push(book);
            }
            stacks.Print();
        }
        /// <summary>
        /// Get Emission by using Factory Design Pattern
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public double GetEmission(string value)
        {
            ITransport transport = null;
            //split user input string, as it contains '-'
            var split = value.Split('-');

            if (split.Length >= 1)
            {
                //Convert first element of splitted string into
                //TransportationCategoryEnum type
                TransportationCategoryEnum transportEnum;
                if (Enum.TryParse(split[0], out transportEnum))
                {
                    //Create trasport object at runtime (Factory desing pattern)
                    switch (transportEnum)
                    {
                    case TransportationCategoryEnum.train:
                        transport = new Train();
                        break;

                    case TransportationCategoryEnum.bus:
                        transport = new Bus();
                        break;

                    case TransportationCategoryEnum.medium:
                        transport = new MediumCar();
                        break;

                    case TransportationCategoryEnum.small:
                        transport = new SmallCar();
                        break;

                    case TransportationCategoryEnum.large:
                        transport = new LargeCar();
                        break;
                    }
                }
            }


            return(getEmissionFromTransportType(value, transport));
        }