Last active
October 2, 2018 19:11
-
-
Save asarnaout/a2074bd5609a20c22b3d9bb85950de53 to your computer and use it in GitHub Desktop.
Flyweight Pattern Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ZoneClient | |
{ | |
static Random rnd = new Random(); | |
public IEnumerable<ShippingRoute> CreateShippingRoutes(IList<string> usZipCodes) | |
{ | |
var routes = new List<ShippingRoute>(); | |
var zoneFactory = new ZoneFactory(); | |
for (var i = 0; i < 2000000; i++) | |
{ | |
var destination = | |
zoneFactory.GetZone(usZipCodes[rnd.Next(usZipCodes.Count)]); | |
if(i % 100 == 0) //Issuing a command on the Value Object | |
destination = destination.RegisterCourier("Fedex"); | |
routes.Add(new ShippingRoute(destination)); | |
} | |
return routes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment