Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created September 28, 2017 10:16
Show Gist options
  • Save NMZivkovic/bdda7584dee802a2e804b10ae70e96c4 to your computer and use it in GitHub Desktop.
Save NMZivkovic/bdda7584dee802a2e804b10ae70e96c4 to your computer and use it in GitHub Desktop.
public class EntityFactory
{
private Dictionary<EntityType, Func<entity>> _entityTypeMapper;
public EntityFactory()
{
_entityTypeMapper = new Dictionary<entitytype, func<entity="">>();
_entityTypeMapper.Add(EntityType.Type0, () => { return new Type0Entity(); });
_entityTypeMapper.Add(EntityType.Type1, () => { return new Type1Entity(); });
_entityTypeMapper.Add(EntityType.Type2, () => { return new Type2Entity(); });
}
public Entity GetEntityBasedOnType(EntityType entityType)
{
return _entityTypeMapper[entityType]();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment