In my own projects, I get the developer to provide me with the dependency provided by the spring DI container.
Recycling the code above, it will look like this:
public interface MyProcessor { // get the implementor to get the hash map WeakHashMap<Function1D, Integer> getParamMap(); default double doSomthingWithParam(double x) { return doSomething() * getParam(); } // uses the implementor getParamMap() to get params default int getParam() { return getParamMap().get(this); } double doSomething(); } public class MyProcessorImp extends SomeClass implements MyProcessor { final WeakHashMap<Function1D, Integer> paramMap = new WeakHashMap<>(); void setParam(int param) { paramMap.put(this, param); } @Override WeakHashMap<Function1D, Integer> getParamMap() { return paramMap; } @Override double doSomething() { // elided } }
source share