I have an Android library used by a decent amount of people, let's call it library A.
I am building a second library, library B.
The two libraries are conceptually related, they solve different problems in the same domain. It's likely that the two libraries will be used together, but it's not mandatory.
The problem: library A contains some classes and interfaces I'd like to reuse in library B.
Are there any best practices on how to do this? This is the first time I encounter this problem and, being the libraries used by other people, I'd like to implement the solution that makes more sense.
I can see three approaches:
- Copy-paste interfaces and classes I want to reuse, from library A to library B.
- Import library A in library B.
- Take out of library A the interfaces and classes I want to reuse, publish them under a new CORE library and import the CORE library in both library A and library B.
Are there more possible approaches I am not considering?
Problems I can see with this solutions:
- This is the worse solution. It doesn't follow the DRY principle and, most importantly, a user of both libraries would end up having interfaces like:
com.libraryA.Interface1
andcom.libraryB.Interface1
. This doesn't allow for nice interaction between library A and B. - Library B would import a bunch of code that it doesn't need. Most importantly, users of library B would always have to import library A, because of the shared interfaces from A to B.
- This seems the most elegant solution, but how should I handle versioning in this situation? Will library A, B and CORE always be required to have the same version number? If not, would it make sense to have different version numbers for A, B and CORE? Changes on CORE would affect both A and B and require a version bump on all three. Changes on A and B would be isolated.
Are there any more problems I am not seeing?