Supplier
Supplier function
A supplier is a function without any parameter, but returns a value.
When to use a supplier function?
When you need a function which supplies a value but there is no input for that.
When code execution is deferred as it is described in this article
In Dotnet there is no such thing as supplier interface like there is in java.
Dotnet uses Func<TResult>
(source)
delegate type for this purpose.
Where it is used
Fun
In the example below there is a silly name creator where the first name and the last name
suppliers are Func<TResult>
delegates.
The delegates are invoked in the Print
method.
The interface where the properties are Func<TResult>
delegate types.
The implementation of the IName
interface.
A test where the IName
is instantiated and executed.