Last active
May 31, 2017 18:48
-
-
Save Kritner/a4165cbdb686364927436851c00ebb4b to your computer and use it in GitHub Desktop.
List of tuples for factory branching removal
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 IFoo { } | |
public class FooOne : IFoo { } | |
public class FooTwo : IFoo { } | |
public class FooFourtyTwo : IFoo { } | |
public class FooFace : IFoo { } | |
public class FooNull : IFoo { } | |
public class Whatever | |
{ | |
public IFoo GetFoo(bool someFlag, string someLabel) | |
{ | |
if (someFlag) | |
{ | |
if (someLabel == "Test" | |
return new FooOne(); | |
if (someLabel == "blah blah") | |
return new FooTwo(); | |
} | |
else | |
{ | |
if (someLabel == "Test" | |
return new FooFourtyTwo(); | |
if (someLabel == "blah blah") | |
return new FooFace(); | |
} | |
return new FooNull(); | |
} | |
} |
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 IFoo { } | |
public class FooOne : IFoo { } | |
public class FooTwo : IFoo { } | |
public class FooFourtyTwo : IFoo { } | |
public class FooFace : IFoo { } | |
public class FooNull : IFoo { } | |
public class Whatever | |
{ | |
private readonly List<(bool someFlag, string someLabel, IFoo someType)> myTypes = new List<(bool someFlag, string someLabel, IFoo someType)>() | |
{ | |
(true, "Test", new FooOne()), | |
(true, "blah blah", new FooTwo()), | |
(false, "Test", new FooFourtyTwo()), | |
(false, "blah blah", new FooFace()), | |
}; | |
public IFoo GetFoo(bool someFlag, string someLabel) | |
{ | |
var result = myTypes | |
.FirstOrDefault(w => w.someFlag == someFlag && w.someLabel == someLabel) | |
.someType; | |
if (result == null) | |
return new FooNull(); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment