Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming DTO and Entity classes

I have two sets of classes in my spring application - DTOs and Entities.

After reading Clean Code by Uncle Bob, I have got hooked on to naming things right more than ever before.

I sat down refactoring one of my Spring projects and I am not sure if adding DTO suffix for DTO classes is the right thing to do. If not, then how do you differentiate between DTO and Entity classes. I do use Service and Repository suffixes for my service classes and repository interfaces.

Merely keeping them under different packages with same names is not helpful esp. when they are to be used in same scope.

Note: Not sure if this is a precise question to be asked on Stackoverflow.

like image 609
comiventor Avatar asked Dec 21 '17 09:12

comiventor


1 Answers

If you read Core J2EE Patterns, 2nd Edition, it is called Transfer Object with all the sample codes having the TO suffix. You can also have a look at Oracle's Core J2EE Patterns site.

To sum up: You should use either DTO or TO as a suffix to any transfer object you use in your business tier.

like image 107
Luay Abdulraheem Avatar answered Sep 29 '22 09:09

Luay Abdulraheem