Ejemplo n.º 1
0
        protected override void ThrowIfComponentIsNotValidForThisVehicleType(Component i_Component)
        {
            eComponentType typeToAdd = i_Component.Type;

            if (typeToAdd != eComponentType.WeightComponent && typeToAdd != eComponentType.HazardousComponent)
            {
                throw new ArgumentException("You can only add weight and hazardous components to a truck.");
            }
        }
Ejemplo n.º 2
0
        protected override void ThrowIfComponentIsNotValidForThisVehicleType(Component i_Component)
        {
            eComponentType typeToAdd = i_Component.Type;

            if (typeToAdd != eComponentType.ColorComponent && typeToAdd != eComponentType.DoorsComponent)
            {
                throw new ArgumentException("You can only add color or doors to a car");
            }
        }
        protected override void ThrowIfComponentIsNotValidForThisVehicleType(Component i_Component)
        {
            eComponentType typeToAdd = i_Component.Type;

            if (typeToAdd != eComponentType.LicenceComponent && typeToAdd != eComponentType.CapacityComponent)
            {
                throw new ArgumentException("You can only add licence and engine capacity components to a motorcycle.");
            }
        }
        private void throwIfComponentAlreadyExists(Component i_Component)
        {
            eComponentType typeToAdd = i_Component.Type;

            foreach (Component component in m_Components)
            {
                if (component.Type.Equals(typeToAdd))
                {
                    throw new ArgumentException("This component type already exists in this vehicle.");
                }
            }
        }
 protected abstract void ThrowIfComponentIsNotValidForThisVehicleType(Component i_Component);
 public void AddComponent(Component i_Component)
 {
     if (i_Component != null)
     {
         throwIfComponentAlreadyExists(i_Component);
         ThrowIfComponentIsNotValidForThisVehicleType(i_Component);
         m_Components.Add(i_Component);
     }
 }