What is the significance of the helper class java?

351    Asked by AndreaBailey in Java , Asked on Oct 12, 2022

What is a helper?

I have seen the name being used everywhere (module names, class names, method names), as if the semantics were deep and meaningful, but in the context of Computer Science (although I don't have a degree in it), I've never seen a description or definition anywhere!


Is it a design pattern? Is it an algorithm? I once worked on a program in which the module and class were both called something helper (where something something was fairly generic too) and I promptly renamed it to something that made sense to me, but I feel like I'm missing something here!,

Answered by Anisha Dalal

A Helper class java is a lesser known code smell where a coder has identified some miscellaneous, commonly used operations and attempted to make them reusable by lumping them together in an unnatural grouping. Successive developers have then come onto the project and not realised that the helper class exists, and have consequently rewritten the same common operations, or even created more Helper classes. But seriously, the main problem with Helper classes is that they are usually operations that act on a specific class, which obviously means in OO terms that they are suffering from an acute case of Feature Envy. This failure to package the behaviour with the data it acts on is why developers so often (in my experience) fail to find it. In addition to this, as you have already identified, SomethingSomethingHelper is actually a terrible name. It is undescriptive, and gives you no real inkling of what sort of operations the class does (it helps?), which also means that it's not obvious when adding new behaviours whether they belong in the Helper class or not. I would break up such classes along the lines of related behaviour that logically group together, and then rename the new classes to reflect what it does.



Your Answer

Interviews

Parent Categories