Give better names to your DTOs

Cassio Mazzochi Molin |

The Java Language Specification states the following regarding the name convention for classes:

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

ClassLoader
SecurityManager
Thread
Dictionary
BufferedInputStream

[…]

Your Data Transfer Object class names should follow the convention mentioned above.


Suffixing a class name with DTO or Dto is not really meaningful and doesn’t tell much about the class itself. Try to give names that describe the purpose of your classes. Here are a few name suggestions you could use:

  • SomeSortOfCommand
  • SomeSortOfConfiguration
  • SomeSortOfCredentials
  • SomeSortOfDetails
  • SomeSortOfElement
  • SomeSortOfEvent
  • SomeSortOfHeader
  • SomeSortOfInstruction
  • SomeSortOfItem
  • SomeSortOfMessage
  • SomeSortOfMetadata
  • SomeSortOfOperation
  • SomeSortOfQueryParameter
  • SomeSortOfQueryResult
  • SomeSortOfRepresentation
  • SomeSortOfRequest
  • SomeSortOfResponse
  • SomeSortOfResult
  • SomeSortOfRow
  • SomeSortOfSettings
  • SomeSortOfSpecification
  • SomeSortOfStatus
  • SomeSortOfSummary
  • SomeSortOfView

Note 1: Whether acronyms will be handled as words or not, I guess it’s up to you. Check the Java API and you will find some stumbles like ZipInputStream / GZIPInputStream. Both classes are in the same package and the name convention is not consistent. HttpURLConnection doesn’t show any consistency with acronyms either.

Note 2: Some names listed above were borrowed from this article written by Richard Dingwall.