Home > Software design >  How to avoid duplicate code in Java when you require the same class in two separated applications?
How to avoid duplicate code in Java when you require the same class in two separated applications?

Time:03-09

For the sake of simplicity, let's say that I have a class named "Dog".

Then I have two separated applications containing implementations of that class.

  1. Application "A" does something with the Dog class.
  2. Application "B" does another something with the Dog class.

Both applications require the Dog class, hence it would be duplicated.


Now let's say for a moment that:

  1. Those applications can't be merged into one.
  2. The implementations from "A" and "B" can't be moved into another application.

I'm using Spring Boot, if that info helps somehow.

Is there a way to fix the duplication of the Dog class?

CodePudding user response:

As @Slaw says you can create a jar/library then use any build tool like maven or gradle and package the jar/library in your archive file when it is built and here is a link for more info https://christianlydemann.com/a-guide-to-sharing-code-between-projects/

  • Related