Skip to content

Instantly share code, notes, and snippets.

@asarnaout
Last active October 2, 2018 19:11
Show Gist options
  • Save asarnaout/a2074bd5609a20c22b3d9bb85950de53 to your computer and use it in GitHub Desktop.
Save asarnaout/a2074bd5609a20c22b3d9bb85950de53 to your computer and use it in GitHub Desktop.
Flyweight Pattern Gist
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