3

Let's say I have a large code base, and I need to concatenate two arrays a few times over the large code base, so I look online for the solution and find a nice little method to accomplish this.

(I could use the whole Apache Commons dependency to use their array concatenate method, but the overhead is pointless for something so niche.)

Should I therefore create a whole util class dedicated to that one function or somehow statically embed it somewhere into the code base? or? What's the convention? Because I seem to be having all of these small completely abstract util methods that would fit perfectly into an api on their own but are unrelated to each other and don't know where to put them. Blame my OCD but having a single ArrayUtils class holding a single method feels wrong, not to mention cumbersome.

I'm not trying to create an array utils library after all. Or am I?

John
  • 346
  • 1
  • 11
  • 1
    Ten different people will say ten different things. There are a lot of literature that just answer your question anyway – nyarian Mar 15 '18 at 06:37
  • I suspected my question might have been answered before, but wasn't sure exactly what to search up to find the answer. – John Mar 15 '18 at 06:39
  • If you only have one array utility method, is it really "cumbersome" to put it in a class by itself? Better to put it there than somewhere random and unrelated. – Andy Turner Mar 15 '18 at 08:36
  • 1
    take a look at this: https://stackoverflow.com/questions/3340032/utility-classes-are-evil – Eirini Graonidou Mar 17 '18 at 21:01

1 Answers1

3

As noted in comments this is highly subjective to the personal taste and practices of the developer.

What I would do is to create that method in a utility class based on functionality. for instance a class called StringTools for utility methods regarding String etc.

For me this makes it easier to keep track of all my utility methods. It's also easy to export it into a jar if necessary.

Brenin
  • 195
  • 1
  • 2
  • 16