What is the best way to implement an interface that combines some instances of the same interface in different ways? I need to do this for multiple interfaces, and I want to minimize the pattern and still achieve good performance, because I need it for a critical production system.
Here is a sketch of the problem.
So I have a generic combiner class that accepts instances and defines various combinators:
class Combiner<I> {
I[] instances;
<T> T combineSomeWay(InstanceMethod<I,T> method) {
}
}
Now, let's say I want to implement the following interface among many others:
Interface Foo {
String bar(int baz);
}
I want to finish the code as follows:
class FooCombiner implements Foo {
Combiner<Foo> combiner;
@Override
public String bar(final int baz) {
return combiner.combineSomeWay(new InstanceMethod<Foo, String> {
@Override public call(Foo instance) { return instance.bar(baz); }
});
}
}
, . , API Java , . , ?