I was just refactoring some code and there were a few places in a class where we needed to instantiate a new instance of something, based on a key... could've used a factory class there, right? Instead i did this:
private readonly Dictionary<string, Func<IPanel>> panelFactory = new Dictionary<string, Func<IPanel>>
{
{ typeAndSizeKey, () => new TypeAndSizePanel() },
{ phaseKey, () => new PhasePanel() },
{ organisationStructureKey, () => new OrganisationStructurePanel() },
{ incidentDataKey, () => new IncidentDataPanel() },
{ processesKey, () => new ProcessesPanel() },
{ generalInfoKey, () => new GeneralInfoPanel() },
{ linksKey, () => new LinksPanel() }
};
and now, when i need to create a new instance i just do this:
panelFactory[myKey]()
i kinda like the simplicity
Pingback: Arjan`s World » LINKBLOG for March 4, 2009