3 Replies Latest reply: Mar 5, 2012 6:07 PM by 796440 RSS

    Best name to class that Do something....

    920854
      Hello !

      I have a doubt about naming Java classes that do something..

      Example: I have a class that calculate an range of year available to generate an report. This class return a list with Last 5 years from 2011... ex: in 2013 the list will return 2012, 2011 etc...

      How can i naming this class?? Its consufing because in the naming conventions it must be an name and not a verb.


      Thanks !
        • 1. Re: Best name to class that Do something....
          EJP
          A class doesn't do anything. A method does something. A class is a holder for methods and state.
          • 2. Re: Best name to class that Do something....
            jschellSomeoneStoleMyAlias
            PaulH wrote:
            Example: I have a class that calculate an range of year available to generate an report. This class return a list with Last 5 years from 2011... ex: in 2013 the list will return 2012, 2011 etc...
            Name = ReportHelper

            The method should be static (as described.)
            • 3. Re: Best name to class that Do something....
              796440
              PaulH wrote:
              Example: I have a class that calculate an range of year available to generate an report. This class return a list with Last 5 years from 2011... ex: in 2013 the list will return 2012, 2011 etc...
              Is that all the class does? It just has that one method? And the method does nothing more than create a list of Integers corresponding to the last 5 years? If so, then I would probably not create a whole class just for that. And if that's not all it does, then it's hard to suggest a name without knowing more about what it really does.

              However, its name should come from a word or phrase that summarizes it responsibilities. The name ReportHelper that was already suggested may be appropriate, or perhaps ReportUtil. On the other hand, if the class isn't specifically just for reports, but does a handful of common tasks that deal with times and dates and calendars that could be used elsewhere in your app, then perhaps TimeUtil, or CalendarHelper would be appropriate. Or, if it is just the one method, then maybe that method should be moved to a ReportGenerator class, where calculating the list of years is one step in the task or generating a report.