Created
May 4, 2020 14:33
-
-
Save gabrielcalegari/c0ac305386a847bddcfbe1a889372433 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 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