Skip to content

Instantly share code, notes, and snippets.

@erikdietrich
Created March 18, 2013 01:12
Show Gist options
  • Save erikdietrich/5184395 to your computer and use it in GitHub Desktop.
Save erikdietrich/5184395 to your computer and use it in GitHub Desktop.
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];
}
private static MailPiece BuildPiece(char key)
{
switch (key)
{
case 'P': return new Postcard();
default: return new Letter();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment