命名DTO和实体类 [英] Naming DTO and Entity classes

查看:330
本文介绍了命名DTO和实体类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的春季应用程序中有两组课程--DTO和实体。

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

在读了Bob叔叔的清洁代码后,我已经迷上了命名的东西比以往任何时候都好。

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

我坐下来重构我的一个Spring项目,我不确定为DTO类添加DTO后缀是否正确。如果没有,那么如何区分DTO和实体类。我确实为我的服务类和存储库接口使用了Service和Repository后缀。

I sat down refactoring a 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 are to be used in same scope.

注意:不确定这是否是Stackoverflow上要求的精确问题。

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

推荐答案

如果您阅读核心J2EE模式,第2版​​,它被称为传输对象,所有示例代码都带有 TO 后缀。您还可以查看Oracle的核心J2EE模式网站。

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.

总结:你应该使用 DTO TO 作为您在业务层中使用的任何传输对象的后缀。

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

这篇关于命名DTO和实体类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆