public void Handle(IList <GpsData> gpsData, IRouteStrategy routeStrategy) { IList <PointLatLng> points = GetRoutePoints(gpsData); var routes = routeStrategy.GetRouteOverlay(points); GetMarkersDistance = routeStrategy.TravelDistance; _gmap.Overlays.Add(routes); _gmap.Zoom++; _gmap.Zoom--; }
} // Стратегию можно менять на лету. Одна из ключевых особенностей паттерна! (Можно вынести в отдельный метод) public GPS(IRouteStrategy strategy) => Strategy = strategy;
public Routeplaner(IRouteStrategy strategy) { Strategy = strategy; }
public Client(IRouteStrategy routeStrategy) { this.routeStrategy = routeStrategy; }
public void SetRouteStrategy(IRouteStrategy routeStrategy) { routeContext = new RouteContext(routeStrategy); }
public void SetStrategy(IRouteStrategy routeStrategy) { this.RouteStrategy = routeStrategy; }
public RouteContext(IRouteStrategy routeStrategy) { this.RouteStrategy = routeStrategy; }
public Navigator(IRouteStrategy strategy) { RouteStrategy = strategy; }
public void SetStrategy(IRouteStrategy strategy) { _strategy = strategy; }
public void Execute(IRouteStrategy strategy, Action <IRouteStrategy> createRoute) { createRoute.Invoke(strategy); }