Created
June 29, 2012 10:17
-
-
Save CraftyFella/3017098 to your computer and use it in GitHub Desktop.
CanIDoSomething DoSomething Pattern
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 | |
{ | |
bool CanFoo(Bar bar); | |
void DoFoo(Bar bar); | |
} | |
public class Thing | |
{ | |
private IEnumerable<IFoo> _foos; | |
public Thing(IEnumerable<IFoo> foos) | |
{ | |
_foos = foos; | |
} | |
public void DoSomthing(Bar bar) | |
{ | |
_foos.Where(a => a.CanFoo(bar)).Each(a => a.DoFoo(bar)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment