Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Utility Classes and Extension through Inheritance

Tags:

java

I have a utility class with some static methods which I use in some places around my code. I am facing a problem now. I want to replace the functions in this utility class in order to provide better implementation. Obviously this cannot be achieved directly without some serious hacking.

My question is: what is the best way to solve this problem. How can someone still use utility classes in such a way that they can still be extended upon. I am thinking around the idea of wrapping the particular utility function for each class that makes use of them so that even if the actual utility method cannot be replaced at least it is possible to replace the class method that calls it. Still, I am curious to know about what are the best practices.

like image 917
Pass Avatar asked Oct 11 '22 16:10

Pass


1 Answers

Why can't you just change the implementation of the static methods in the utility class.

As long as you don't change the method signatures, the users wont get affected.

like image 100
Suraj Chandran Avatar answered Nov 17 '22 10:11

Suraj Chandran