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
static void Main(string[] args) | |
{ | |
var factory = new MailPieceFactory(); | |
var zipCodes = new List<int>(); | |
for (int index = 0; index < 23458333; index++) | |
{ | |
zipCodes.Add(index % 100000); | |
var randomPiece = factory.GetPiece(GetRandomKey()); | |
string pieceStatistics = randomPiece.GetStatistics(zipCodes[index]); |
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 MailPieceFactory | |
{ | |
private readonly Dictionary<char, MailPiece> _mailPieces = new Dictionary<char,MailPiece>(); | |
public MailPiece GetPiece(char key) | |
{ | |
if (!_mailPieces.ContainsKey(key)) | |
_mailPieces[key] = BuildPiece(key); | |
return _mailPieces[key]; |
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 abstract class MailPiece | |
{ | |
public abstract decimal Postage { get; set; } | |
public abstract decimal Width { get; set; } | |
public abstract decimal Height { get; set; } | |
public abstract decimal Thickness { get; set; } | |
public string GetStatistics(int zipCode) | |
{ | |
return string.Format("Zip code is {0}, postage is {1} and height is {2}", |
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
static void Main(string[] args) | |
{ | |
var zipCodes = new List<int>(); | |
var letter = new Letter(); | |
for (int index = 0; index < 23458333; index++) | |
{ | |
zipCodes.Add(index % 100000); | |
string pieceStatistics = letter.GetStatistics(zipCodes[index]); | |
Console.Write(pieceStatistics); | |
} |
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
static void Main(string[] args) | |
{ | |
var zipCodes = new List<int>(); | |
var letter = new Letter(); | |
for (int index = 0; index < 23458333; index++) | |
{ | |
zipCodes.Add(index % 100000); | |
Console.Write(string.Format("Zip code is {0}, postage is {1} and height is {2}", | |
zipCodes[index], letter.Postage, letter.Height)); | |
} |
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
static void Main(string[] args) | |
{ | |
var pieces = new List<MailPiece>(); | |
for (long index = 0; index < 563000000; index++) | |
{ | |
pieces.Add(new Letter() { DestinationZip = (int)(index % 100000) }); | |
} | |
Console.ReadLine(); | |
} |
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
static void Main(string[] args) | |
{ | |
var pieces = new List<MailPiece>(); | |
for (long index = 0; index < 23458333; index++) | |
{ | |
pieces.Add(new Letter() { DestinationZip = (int)(index % 100000) }); | |
} | |
Console.ReadLine(); | |
} |
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 Postcard : MailPiece | |
{ | |
public override decimal Postage { get; set; } | |
public override decimal Width { get; set; } | |
public override decimal Height { get; set; } | |
public override decimal Thickness { get; set; } | |
public Postcard() | |
{ | |
Postage = 0.33M; |
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 abstract class MailPiece | |
{ | |
public abstract decimal Postage { get; set; } | |
public abstract decimal Width { get; set; } | |
public abstract decimal Height { get; set; } | |
public abstract decimal Thickness { get; set; } | |
public int DestinationZip { get; set; } | |
} |
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 Letter : MailPiece | |
{ | |
public override decimal Postage { get; set; } | |
public override decimal Width { get; set; } | |
public override decimal Height { get; set; } | |
public override decimal Thickness { get; set; } | |
public Letter() | |
{ | |
Postage = 0.46M; |
NewerOlder