Reputation: 5725
I have a method:
private Replace ReplaceType(final ReplaceTypeDao replaceTypeDao, final Long key) {
final Optional<ReplaceType> replaceTypeEntry = replaceTypeDao.findById(key, true);
if (!replaceTypeEntry.isPresent()) {
throw new TypeIsMissing(key);
}
return replaceTypeEntry.get();
}
which is exactly the same in other classes but from different packages. I could create class (but in which package?) with method replaceTypeProcess
, then call new class constructor and newClassInstance.replaceTypeProcess()
but I don't like this solution. How to do it in best manner?
Upvotes: 0
Views: 345
Reputation: 464
You can create a package utility
And put some common classes in it.
You can also look this link on how to remove duplicate method.
And as you mentionned it you can make a static method. Here is a very nice post about the use of static methods.
Upvotes: 2