How call that class\structure ? Maybe is it design pattern ?
Task:
I have a collection which I need search item.
I have 3 levels for searching.
I create a Matcher chain and search in collection on each levels and pass the collection to next level if doesn't find.
I'm looking for what is design pattern.
class Matcher
{
private readonly Matcher _nextMatcher;
private readonly Func<lambda, bool> _predicate;
public Matcher(
Matcher nextMatcher,
Func<lambda, bool> predicate)
{
_nextMatcher = nextMatcher;
_predicate = predicate;
}
public bool Match(Collection<SomeObject> someObjects,
IEnumerable<SomeObject> sourceObjects)
{
if (!_predicate(someObjects, sourceObjects))
{
if (_nextMatcher == null)
return false;
return _nextMatcher.Match(someObjects, sourceObjects);
}
return true;
}
}
From the looks of it, this looks like (a correct) implementation of the Chain of Responsibility design pattern.
Here's another, more .NET-centric example: http://www.dofactory.com/Patterns/PatternChain.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With