Search code examples
javaoopopen-source

What do i do if need to change a libraries functionality


I have a class in a Java Library(open-m3u) that I need to change just slightly. The functionality is easy to implement on my own without using the library. The library is open-source so i have access to all of its code. The class is made in such a way that inheriting it or even changing that small part is not possible. My question is should I copy that class and all the classes that it depends on and put them in my own code base and change the functionality or should implement the functionality myself. Or is there another option?


Solution

  • The functionality is easy to implement on my own without using the library.

    IMHO, then that's the way to go. Your other options are:

    • Build the functionality around the library: you say that's not possible in your case.
    • Create a branch of the library in your own source control system. That means you'll have to keep that repository in sync with the library maintainers, which means a permanent burden. And you have to check what the library's license says about forking.
    • Copy the relevant parts into your code base and do the modifications there. Then you won't profit from future enhancements or bug fixes, but still have to maintain code that was created and architected by someone else, and doesn't exactly fit your requirements. And you have to check what the library's license says about copying parts into a foreign code base.

    They all have their drawbacks.

    As a general remark: in 25 years of professional software development, I've seen both successful usages of external libraries as well as complete failures. Some times, we invested more time into evaluating existing libraries (and then finding out that nothing matched) than we needed for implementing the project-specific solution on our own.

    And every library you can do without, makes config management and rollout easier.