Reputation: 2604
May be wrong place to ask (please direct) but:
I often use a variance of the Strategy pattern where I write like this:
interface IA
{
bool CanHandle(T someParameter)
void Handle(T someParamter)
}
class A1:IA {}
class A2:IA {}
I then have a class where IEnumerable<IA>
is injected, the First/Single/All of the instances is found through CanHandle()
and called on Handle()
.
IS there a name for this pattern?
Upvotes: 0
Views: 67
Reputation: 233125
In the .NET world this is known as the Test/Doer idiom. It's isomorphic to another .NET idiom usually known as TryParse, and both are isomorphic to the Maybe container, which can be defined from an F-algebra. It doesn't get much more foundational than that.
Upvotes: 3