Created
March 18, 2013 01:12
-
-
Save erikdietrich/5184395 to your computer and use it in GitHub Desktop.
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]; | |
} | |
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