What are helper objects in java?

后端 未结 6 407
无人共我
无人共我 2021-01-30 11:04

I come across few of the times called helper objects... can anybody elaborate what are those helper objects and why do we need them?

6条回答
  •  [愿得一人]
    2021-01-30 11:30

    A 'helper' method is typically a method to make something easier, whatever it is. Sometimes they're used to make things more readable/clearly organized (some may argue this, but it's ultimately very subjective):

    public void doStuff() {
       wakeUp();
       drinkCoffee();
       drive();
       work();
       goHome();
    }
    

    Where, each 'helper method' on their own are fairly complex... the concept becomes really clear and simple.

    Another very good use of helper methods is to provide common functionality across many different classes. The best example of this is the Math class which contains a ton of static helper methods to help you calculate things like the log of a number, the exponent of a number... etc.

    Where you draw the line as to what's a helper method and what's just a regular method is pretty subjective, but that's the gist of it. Other answers here are pretty good too.

提交回复
热议问题