Skip to content

Instantly share code, notes, and snippets.

@gabrielcalegari
Created May 4, 2020 14:33
Show Gist options
  • Save gabrielcalegari/c0ac305386a847bddcfbe1a889372433 to your computer and use it in GitHub Desktop.
Save gabrielcalegari/c0ac305386a847bddcfbe1a889372433 to your computer and use it in GitHub Desktop.
public interface IReport
{
string Generate();
}
public class ReportA : IReport
{
public string Generate()
{
return "Report A";
}
}
public class ReportB : IReport
{
public string Generate()
{
return "Report A";
}
}
public enum ExampleEnum
{
StrategyA,
StrategyB,
}
public interface IReportFactory
{
IReport GetInstance(ExampleEnum exampleEnum);
}
public class ReportFactory : IReportFactory
{
public IReport GetInstance(ExampleEnum exampleEnum)
{
switch(exampleEnum)
{
case ExampleEnum.StrategyA:
return new ReportA();
case ExampleEnum.StrategyB:
return new ReportB();
default:
// is there a default case? if yes, return it.
// else throw an exception
throw new NotImplementedException("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment