This implementation follows the idea of the following blog entries.
With an implementation of code kata Bowling from this blog entry:
The following classes in folder src/test/java shows how to implement the flow
API from blog with Java 8:
MethodsCheatSheetshows how to transfer functional units into simple methods.DelegatesCheatSheetshows how to transfer functional units into methods with delegation to return values.EventsCheatSheetshows how to transfer functional units into classes with events.BowlingGameshows how to implement the bowling kata with flow design.
Also there is a class Program shows how to implement a complete program.
For productive use there are following classes in the framework:
FunctionalUnitis a base class or template for a functional unit with one input pin and one output pin.- Use class
OutputPinas public final member or private member with getter for output pins of a functional pins. - Use functional interface
InputPutas public method for input pins of a functional pins. - Use class
Flowas template to design a flow application. This class initialize and start the flow of the application
public abstract class MyFunctionalUnit<I, O> {
public final OutputPin<O> result = new OutputPin<>();
public void process(I input) {
// process input and publish output
O output = ...
result.publish(output);
}
}
With one value:
MyFunctionalUnit<String, Integer> fu1 = new MyFunctionalUnit<>();
MyFunctionalUnit<Integer, String> fu2 = new MyFunctionalUnit<>();
fu1.result.connect(fu2::process());
fu1.result.publish("Foo");
Without value:
MyFunctionalUnit<String, Void> fu1 = new MyFunctionalUnit<>();
MyFunctionalUnit<Void, String> fu2 = new MyFunctionalUnit<>();
fu1.result.connect(fu2::process());
fu1.result.publish(null);