Skip to content

Instantly share code, notes, and snippets.

@rushfrisby
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rushfrisby/8368c0393accbee4cd97 to your computer and use it in GitHub Desktop.
Save rushfrisby/8368c0393accbee4cd97 to your computer and use it in GitHub Desktop.
RulePlex Strategy Pattern Example
//do this once and cache it
var ruleEngineTypes = new Dictionary<LanguageTypes, Type>();
ruleEngineTypes.Add(LanguageTypes.CSharp, typeof(CSharpRuleEngine));
ruleEngineTypes.Add(LanguageTypes.Python, typeof(PythonRuleEngine));
ruleEngineTypes.Add(LanguageTypes.JavaScript, typeof(JavaScriptRuleEngine));
//switch turns into this...
var ruleEngineType = ruleEngineTypes[policy.LanguageType];
var engine = (IRuleEngine)Activator.CreateInstance(ruleEngineType);
engine.Execute(plan);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment