Search code examples
javareusabilitycode-reuse

Reusing code and generic implementations between different projects


It seems to me that there are many instances where implementation of a specific class is the same for different projects.

In Java this is true for classes like ArrayList. So there is obviously reason to reusing generic classes across different projects.

Another generic class that would be usefull would then be ArrayMatrix, but since there is no default implementation in Java I made one myself. It's generic, safe and documented.

Is it common practice to create your own implementation in a situation like this?

If not, what's the preffered way?

If it is, what's the best practice way to share the class/code between projects and organize your "library"?


Solution

  • This is the entire point of having libraries. The best way to share them is to put them in an artifact repository; if possible, Central and JCenter, or some company-internal repository if the libraries can't be open-sourced for some reason. Here's the intro to publishing to Central; it's a minor hassle, but I've done it myself, and it's not too difficult.

    I would encourage you to make sure that an equivalent to your class isn't already available in something like Guava or Apache Commons.