Suppose we have a domain in which we can generalise some operation by passing in a function, like the
map functions. Now suppose that the function we pass in has some domain specific name, and fixed parameter types. Let's call it a
We can approach defining a
BazFunction in two ways:
- As a delegate:
Bar delegate BazFunction(int x)
- As a lambda:
Their usage when calling the operation is identical (
Foo((x) => x)) but the function definition is different
public Bar Foo(Func<int, Bar> baz) public Bar Foo(BazFunction baz)
The obvious benefit of using a delegate is the readability, at least to somebody familiar with the domain.
What are the cons of such an approach? Both technical and non-technical.