Пример #1
0
        public Car(IAlarm alarm, SeatBelt seatBelt, CarSpeedSimulator carSpeedSimulator, Speedometer speedometer, SpeedAlarm speedAlarm)
        {
            _alarm             = alarm;
            _seatBelt          = seatBelt;
            _carSpeedSimulator = carSpeedSimulator;
            _speedometer       = speedometer;
            _speedAlarm        = speedAlarm;

            speedAlarm.SetAlarm(alarm);
            speedAlarm.SetSpeedSource(speedometer);

            seatBelt.SetAlarm(alarm);
            seatBelt.SetSpeedSource(speedometer);
        }
Пример #2
0
        //This is not actual builder pattern
        private static Car BuildCar(string carType, string mode)
        {
            var simulator   = new CarSpeedSimulator();
            var speedometer = new Speedometer(simulator);

            IAlarm alarm = AlarmFactory.CreateAlarm(carType);

            alarm = new VerifyingAlarmProxy(alarm, mode);

            var speedAlarm = new SpeedAlarm();

            var seatBelt = new SeatBelt();

            Car car = new Car(alarm, seatBelt, simulator, speedometer, speedAlarm);

            return(car);
        }