Scenario:
- I have two Libraries which are essentially doing same things but in a different way
- Their parameter types, return types and even method names are different from each other.
- I need to design a class which at the very beginning decides whether it needs to chose Library A or Library B for its working throughout the code
I am using an abstract class with generics to define the template of the common interface
public abstract class LibraryInterface<A,B,C> {
public abstract List<B> methodA(A a,B b,C c);
public abstract List<C> methodB(B b);
public abstract List<A> methodC();
}
It has 2 implementations, each for Library A and Library B
public class LibraryA extends LibraryInterface<ObjectA,ObjectB,ObjectC> {
@Override
public List<ObjectB> methodA(ObjectA a,ObjectB b,ObjectC c) {
// do something
}
@Override
public List<ObjectC> methodB(ObjectB b) {
// do something
}
@Override
public List<ObjectA> methodC() {
// do something
}
}
public class LibraryB extends LibraryInterface<ObjectD,ObjectE,ObjectF> {
@Override
public List<ObjectE> methodA(ObjectD d,ObjectE e,ObjectF f) {
// do something
}
@Override
public List<ObjectF> methodB(ObjectE e) {
// do something
}
@Override
public List<ObjectD> methodC() {
// do something
}
}
Problem:
- I need to chose a particular implementation at the start of my client code and then use it throughout.
- However I cannot couple my client code with specific implementation of a Library.
How do I design my client code to effectively use these libraries.
UPDATE: 1.Plugin system does not solve for my client code issue which needs to heavily work with one of the library implementations