public void ResolveStrategyAlgorithms(TransportTypesEnum transportType) { switch (transportType) { case TransportTypesEnum.Bus: this.ContextStrategy.setStrategy(new PublicAlgorithm()); break; case TransportTypesEnum.Car: this.ContextStrategy.setStrategy(new CarAlgorithm()); break; case TransportTypesEnum.Bicycle: this.ContextStrategy.setStrategy(new BicycleAlgorithm()); break; case TransportTypesEnum.Walk: this.ContextStrategy.setStrategy(new WalkAlgorithm()); break; default: this.ContextStrategy = null; throw new NotSupportedException("The transport type is not supported! Please use an existing transport type."); } }
public static bool ResolveStrategy(this Client c, TransportTypesEnum transportType) { try{ c.ResolveStrategyAlgorithms(transportType); return(true); } catch (Exception ex) { Console.WriteLine(" - There was an error trying to resolve the algorithm."); Console.WriteLine($" - Error: {ex.Message}"); } return(false); }