Skip to content

Instantly share code, notes, and snippets.

@CraftyFella
Created June 29, 2012 10:17
Show Gist options
  • Save CraftyFella/3017098 to your computer and use it in GitHub Desktop.
Save CraftyFella/3017098 to your computer and use it in GitHub Desktop.
CanIDoSomething DoSomething Pattern
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